Garbage collection - able to force it?

D

dd

I have a situation where the browser memory goes up and up
as each Ajax call causes new content to be deployed into a
DIV. I'd like to know if I can force garbage collection to occur.

More detail:

My code is loaded in an iframe which is in a div. The parent
page looks like this (my code is in firstiframe.html):

<div id="main div">
some content that will get replaced via Ajax calls
</div>
<div id="abc">
<iframe src="firstiframe.html" bla bla>
</div>

What the parent page does is, each time the user clicks on
some menu that causes some Ajax function to load new
content into the "main div" (e.g. a webmail page and the
user clicks on an email to open it), then the parent page
loads the new content into that main div, and at the same
time, it loads a different iframe into the innerHTML of that
div "abc".

My job, in the code in the iframe, is to dynamically insert
things into the parent page. All those things I insert into
the parent page though, must be inside the "abc" div. What
I do is, get a handle to the iframe (e.g. parent.frames[0], or
parent.getElementsByTagName('iframe').item(myiframe))
and then I insertAdjacentElement("afterEnd",newelement).

So all divs and script elements I add, are encapsulated
within div "abc" and are therefore manageable by the
parent page. What it does is, when it's doing it's Ajax
pseudo-navigation, and just prior to loading a new iframe
into "abc", is to loop through the child nodes of "abc" and
remove all the elements. It's effectively nuking everything
I added. I don't have any control over how it's doing that,
it's nothing to do with me. It appears to work though.

The problem I've noticed though, is that memory just goes
up and up and up each time one of these pseudo navigations
occurs, leading me to think that although the nodes are
being removed, they're somehow hanging on. Perhaps it's an
issue with closures persisting, or setTimeout or setInterval
having a refcount on a function, or the ActiveX controls that
were on some of the DIV's that I inserted are still running.

If I could influence garbage collection (even if just manually
from the address bar as a test) then I could see if that helps.

I'm fairly limited in what I am able to do, but I do get to give
feedback to the authors of the code that "nukes" the "abc"
div contents and can advise them that it might be their fault
that memory is increasing. I'm not sure of this though, it
could easily be my fault.

I've thought about doing a test where I keep going and going
and seeing if the browser does eventually manage it's garbage
but haven't done that yet.
 
D

dd

I also meant to add this question to the initial post:

Can anyone think of a better way of detecting that
one of these pseudo navigations has occurred? The
onunload event in my iframe is not firing properly. I
guess the browser (IE at least anyway) only fires the
event when either a full browser navigation occurs, or
the user closes the browser, or the iframe is navigated
to somewhere else. When the iframe element simply
gets nuked (removed from the DOM) it seems that the
event doesn't occur. What I've tried doing to workaround
this, is to have some code running on a setInterval and
checking for the existence of one of the child divs that I
created inside "abc". If it detects that this child div no
longer exists, it calls my onunload handler and cancels
the setInterval.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top