<div dir="ltr">2013/7/17 L. David Baron <span dir="ltr"><<a href="mailto:dbaron@dbaron.org" target="_blank">dbaron@dbaron.org</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">On Tuesday 2013-07-16 16:51 -0700, Justin Lebar wrote:<br>
> On Tue, Jul 16, 2013 at 4:49 PM, Felipe G <<a href="mailto:felipc@gmail.com">felipc@gmail.com</a>> wrote:<br>
> >> The bad news is that there's a new way to leak that you should be aware<br>
> >> of.<br>
> ><br>
> > Why do you say this is a new way to leak? Did this not leak before, and the<br>
> > fix for the |document| leak will introduce it?<br>
><br>
> It's only "new to me" -- there's no fix for the |document| leak (it<br>
> probably was a figment of our collective imagination), and afaik the<br>
> closure behavior has been in place for a long time.<br>
<br>
</div>For what it's worth, I think the old behavior was substantially<br>
*leakier*. When I wrote<br>
<a href="http://www.mozilla.org/scriptable/avoiding-leaks.html" target="_blank">http://www.mozilla.org/scriptable/avoiding-leaks.html</a> in 2005, which<br>
has now been migrated to<br>
<a href="https://developer.mozilla.org/en-US/docs/Using_XPCOM_in_JavaScript_without_leaking" target="_blank">https://developer.mozilla.org/en-US/docs/Using_XPCOM_in_JavaScript_without_leaking</a><br>
I believe the behavior was that all the variables in the containing<br>
scope were entrained by the closure, whether the closure used them<br>
or not. Limiting this to only variables used by some closure is a<br>
more recent optimization.<br></blockquote><div>It seems that most of what you wrote under <a href="https://developer.mozilla.org/en-US/docs/Using_XPCOM_in_JavaScript_without_leaking" target="_blank">Using_XPCOM_in_JavaScript_without_leaking</a> applies to general-purpose JS. Do you mind if I (or anyone) move that content to a more generic MDN page about JS memory management?<br>
<br></div><div>Since we're talking about memory management in JS, I encourage all Gaia/web devs to read:<br><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management</a> (there is some overlap with the Usign XPCOM in JS without leaking page)<br>
</div><div>I also recently gave a JS dev-oriented talk on the topic with some pretty drawing of graphs:<br><a href="https://www.youtube.com/watch?v=ADiF5UUKDCk">https://www.youtube.com/watch?v=ADiF5UUKDCk</a><br><br></div>
<div>Thanks,<br></div><div><br></div><div>David<br></div></div></div></div>