[Javascript] AJAX app causing excessive browser memory usage

Rick Emery rick at emery.homelinux.net
Thu May 18 20:16:08 CDT 2006


Quoting Paul Novitski <paul at juniperwebcraft.com>:

> At 04:12 PM 5/18/2006, Rick Emery wrote:
>> I have a web application in which the data in a table is refreshed
>> every 30 seconds. I'm using AJAX to get the data.
> ...
>>   tmpBody = document.getElementById("eltable").replaceChild(tbody, oldBody);
> ...
>> In both Internet Explorer and Firefox, I can see that, each time the
>> xhr response is received and the data updated, the memory consumption
>> of the browser  process increases. I expect this if the new table body
>> has more rows than the old table, but it happens even when there are
>> fewer rows. If I let it run over the weekend, it will eventually
>> consume all of the available memory of the machine. Closing the
>> browser is the only way to free the memory.
>
>
> I wonder if it's replaceChild that's the culprit.  Have you tried using
> removeChild and appendChild instead?

That's an easy one...I'll give that a try.

> I also wonder whether it has to do with replacing a parent element that
> has child nodes.  If so, it might help to walk the DOM removing all the
> children within the table body before removing or replacing it.

I'll try this too.

> I just got 155,000 hits by googling [ajax memory leak] and 78 hits for
> [ajax memory leak replacechild], so you might find answers out there on
> the net.

Believe it or not, Google is my best friend when I run into problems.  
That said, I'm ashamed to admit that I didn't even think to do that  
with this problem. I guess I just assumed that all of the books and  
articles I've read would have addressed it (for example, I'm using an  
eventcache script to attach/remove events as per all of the IE memory  
leak articles I've read).

Thanks for the ideas; I'll report back after I've tried them.

Rick
-- 
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
  with your eyes turned skyward, for there you have been, and there
  you will always long to return"
                                               -- Leonardo Da Vinci




More information about the Javascript mailing list