i had yet another dive into javascript memory leaks. my question arose while reading Ilya Kantor's article.
i am aware of ie's memory-leak caused by circular references between DOM-/COM-objects and javascript objects as Ilya points out.
i am also aware of memory-leaks caused by inner functions' lexical environment being implemented as a singleton explained by david glasser.
my case is different: which javascript engines, if any, would leak data
i.e. allocate data
to wrapped
's lexical environment although there's no reference in the following example?
function factory () {
var data = 'bytebytebyte';
function wrapped () {
// (1), pass
}
// (2), clean up?
return wrapped;
}
wrapped
has no reference todata
- would you have to set
data=null
anyway to not leak it?
Ilya says (if data
was set to null
)
Now the data still remains in memory as the property of LexicalEnvironment, but it doesn’t occupy so much space.
David says
Fortunately, JavaScript implementations (or at least current Chrome) are smart enough to notice that
data
isn’t used inwrapped
[...]
Scott Christopher raised a similar if not the same question in his answer.
this is too vague, a definite answer would be great! maybe someone even happened to draw a mem-usage graph on an ie-vm while setInterval
-ing the factory
method above?