From 22dafa658bdf5536c3002e7f312efe0dfbc7236d Mon Sep 17 00:00:00 2001 From: arturovt Date: Thu, 19 Sep 2024 13:11:07 +0300 Subject: [PATCH] fix(http): cleanup JSONP script listeners once loading completed (#57877) This commit removes event listeners from the `script` element once loading is complete. If the element is not garbage collected properly, in Firefox, the script element still appears in the memory tree view, captured by `__zone_symbol__loadfalse -> HTMLScriptElement -> GC Roots`. We should always be good citizens and clean up event listeners when we no longer need them, as browser's garbage collectors work differently. Calling `remove()` on the node doesn't guarantee that the node can be collected. PR Close #57877 --- packages/common/http/src/jsonp.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/common/http/src/jsonp.ts b/packages/common/http/src/jsonp.ts index 73e11a3e6f4..f4a70158eff 100644 --- a/packages/common/http/src/jsonp.ts +++ b/packages/common/http/src/jsonp.ts @@ -163,6 +163,9 @@ export class JsonpClientBackend implements HttpBackend { // the response callback from the window. This logic is used in both the // success, error, and cancellation paths, so it's extracted out for convenience. const cleanup = () => { + node.removeEventListener('load', onLoad); + node.removeEventListener('error', onError); + // Remove the