Hiermenus Go Forth, XXIII - DHTML Lab | 2 | WebReference

Hiermenus Go Forth, XXIII - DHTML Lab | 2


Hiermenus Go Forth, XXIII:
Version 4.1.1 - The Complete Script (Full-Window)

The IE Memory Problem

On the HM Known Issues page, we described the problem in this way:

"Memory, allocated to a page running HM, is not freed when the user navigates away from the page, but only when IE is closed.

On the Macintosh, this causes a notable cumulative sluggishness in HM creation on subsequent pages.

On Windows, no HM creation speed problem is noted, and user browsing experience is unaffected. Of course, if the user continues to visit pages with HM throughout the browser session, memory will eventually run out. But memory depletion has only been reported in test sessions where developers have loaded HM continuously for hours, and not in regular user navigation."

The cause has been identified as:

Memory allocated to custom JavaScript variables referencing DOM elements is not freed.

The problem is compounded if the JS variables themselves have properties which reference other elements, especially positioned elements.

The solution:

  1. Keep track of all new DOM elements in the HM script.

  2. When the user leaves the page, free allocated memory by setting the JS variables that refer to these elements to null.


Run the following script in IE5+, with your memory monitor utility (ex. TaskManager in WinNT/2000) open, to see memory allocated. Reload the page. More memory is used. Keep reloading. You will notice that used memory is not freed and more is allocated. Eventually you will run out.

for (i=0;i

If you are not familiar with tracking memory usage on your system, then take my word for it. If you are, you can either cut-and-paste the above script into one of your pages, or click here to run the script in a new window:

IE memory problem example

Note: Windows 95/98 do not have a built-in memory-monitoring utility. You will need to download one from the many software download sites. Example: TaskInfo 2000


Many thanks to Michael van Ouwerkerk for pointing out the forest hidden among the trees, and leading to the solution.

Thanks also to:
Simon Choy, who tested a successful beta of 4.1.1, and to
Michael DeCourcey at PlumTree and
Philip Petrescu at EasyStat
who tested an unsuccessful beta. Sorry guys, I sent you the wrong file!

On the next page, the changes made in 4.1.1.

Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: October 2, 2001
Revised: October 2, 2001

URL: http://www.webreference.com/dhtml/column59/2.html