Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ export class IframeExecutionService extends AbstractExecutionService<Window> {
}

protected terminateJob(jobWrapper: TerminateJobArgs<Window>): void {
document.getElementById(jobWrapper.id)?.remove();
const iframe = document.getElementById(
jobWrapper.id,
) as HTMLIFrameElement | null;
if (iframe) {
// Navigate to about:blank before removing to ensure the browser
// unloads the previous document and cleans up its event listeners.
// Without this, Firefox may keep the detached iframe's document alive
// with all its event listeners, causing a memory leak.
iframe.src = 'about:blank';
iframe.remove();
}
}

protected async initEnvStream(snapId: string): Promise<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,19 @@ export class BaseSnapExecutor {
data.runningEvaluations.forEach((evaluation) => evaluation.stop()),
);
this.snapData.clear();

// Clean up global error handlers to prevent memory leaks.
// Without this, the event listeners keep references to the executor
// and prevent the iframe from being garbage collected.
if (this.snapPromiseErrorHandler) {
removeEventListener('unhandledrejection', this.snapPromiseErrorHandler);
this.snapPromiseErrorHandler = undefined;
}

if (this.snapErrorHandler) {
removeEventListener('error', this.snapErrorHandler);
this.snapErrorHandler = undefined;
}
}

// TODO: Either fix this lint violation or explain why it's necessary to
Expand Down