I am worried about memory leaks in my javascript application.
I attach objects to html elements like this:
function obj(div)
{
this.div = div;
div.obj = this;
}
and that circular reference is obviously memory leak risk. If the div is deleted
by overwriting its parent’s innerHTML, do the objects get garbage-collected?
How can I be sure? (This is the main reason I wish there was a javascript destructor:
to confirm object deletion.)
One way to eliminate the circular reference is to avoid one of the references, probably
“this.div = div,” but that could require searching large portions of the document to find
the div when it’s needed. I don’t want to burden the application that way if it’s not
necessary.
I have not been able to find online wisdom about this (or possibly I’ve found but not
recognized the answer). Can someone enlighten or reassure me?
Thanks,
Chuck Jungmann