Skip to content

Commit 22dafa6

Browse files
arturovtdevversion
authored andcommitted
fix(http): cleanup JSONP script listeners once loading completed (angular#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 angular#57877
1 parent 7bfe62a commit 22dafa6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/common/http/src/jsonp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ export class JsonpClientBackend implements HttpBackend {
163163
// the response callback from the window. This logic is used in both the
164164
// success, error, and cancellation paths, so it's extracted out for convenience.
165165
const cleanup = () => {
166+
node.removeEventListener('load', onLoad);
167+
node.removeEventListener('error', onError);
168+
166169
// Remove the <script> tag if it's still on the page.
167170
node.remove();
168171

0 commit comments

Comments
 (0)