On 12/25/10, Balázs Galambosi <galambal...@gmail.com> wrote:
> 2010/12/25 Garrett Smith <dhtmlkitc...@gmail.com>:
>>> In this case, I still have a memory leak?
>> Yes, you do. But what are you doing there?
>
> Alright. Now I'm not sure what the real code in Yu's head looks like,
> but when I first read I thought he meant something like:
>
> function outer() {
>      var div = document.createElement("div");
>      // do something with div
>      // ...
>      function inner() {
>         var a,b,c;
>         // do something without div
>         // ...
>      }
>      outer = inner;
>      return inner();
> }
>
> There is no leak in this case. The memory usage is stable
> in IE for 10 000 calls: http://jsbin.com/oriqa4/
>
There is a leak of exactly one `div`, which cannot be GC'd. If the
only reference the dom element is `div`, then setting `div` to null
means nothing is pointing at that element, making it eligible for GC.

A leak of exactly one div means that memory won't increase on
subsequent calls. Memory usage should therefore be stable and not
increase.
-- 
Garrett

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to