I've got a simple loop that creates and destroys (hopefully) empty objects: http://jsfiddle.net/TgWze/
function Test()
{
}
function generate()
{
for(var i = 0; 1000 > i; ++i)
{
var view = new Test();
delete view;
}
}
The memory profile in Chrome/Safari shows memory-leak like behavior if I keep clicking the link: http://cl.ly/BnCV
Am I missing something?
3 Answers 3
That looks like normal GC behavior. Once there are too many objects, the GC cleans them up.
It would only be a memory leak if the troughs after each peak (just after the GC runs) get successively higher, indicating that the GC didn't catch everything.
Comments
It's managed memory. So it will collect the deleted object at some point when the garbage collector runs. You deleting the objects actually doesn't do anything. However since, view is never reference, it should be collected easily.
2 Comments
new does allocate some memory; delete does not deallocate itThat code does not leak.
To convince yourself you can take snapshots of the memory and compare before and after. Have a look at this guide that I wrote, for more details: http://www.vladalexandruionescu.com/2012/08/javascript-memory-leaks.html.
Comments
Explore related questions
See similar questions with these tags.
deletelike that; it's only for deleting properties in an object.