When the code contained in the element scriptis evaluated, the result of this code evaluation becomes part of the page runtime. Removing an element scriptdoes not remove the resulting structures (functions, etc.) from the environment.
So, if a script defines functions or intercepts event handlers for elements or creates new properties for existing objects (including a global object), these functions, handlers and properties remain in memory, even if scriptcertain of them are deleted from the DOM (as usual JavaScript garbage collection, for example, objects that are not referenced anywhere are eligible for the GC, but the element scripthas nothing to do with it). An element scriptis just a mechanism for passing code to a browser.
source
share