By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

Garbage collection - able to force it?

P: n/a
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 id="abc">
<iframe src="firstiframe.html" bla bla>

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(myifram e))
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.

Feb 1 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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.

Feb 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.