[Greasemonkey] access to injected scripts?

Jeremy Dunck jdunck at gmail.com
Mon May 30 14:27:18 EDT 2005


On 5/30/05, Bill Donnelly <donnelly at snowcrest.net> wrote:
> So the script stays around because it begins executing when you load it,
> and it is an object that is being referenced by something, even though
> you remove it from the DOM. So the DOM reference is gone.
> But how does it know when to free that object and its memory?
> When you close the window? When you surf to another page in
> that same window? When you close Firefox? I'm just wondering
> in a programming and design and "memory leak" sense.

The DOM and the JS scope chain are really separate things.
When the browser parses a <script> tag, it loads and evaluates the
associated code immediately.  The script tag then just sits and does
nothing for the remainder of the page's life.  Removing the script
does not change the fact that the script was evaluated.

If you remove this elem after it is evaluated, would you expect
window.foo to be set back to undefined or something?  :)
<script ...>
window.foo = 'bar';
</script>


More information about the Greasemonkey mailing list