spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com


home / experts / dhtml / column59

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Logo

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.

Example

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.

<SCRIPT>

for (i=0;i<100;i++) {
    menuElement = document.createElement('DIV');
    document.body.appendChild(menuElement);
    for(j=0;j<10;j++){
        ItemElement = document.createElement("DIV");
        ItemElement.style.position = "absolute";
        ItemElement.parent = menuElement;
        ItemElement.parent.child = ItemElement;
        menuElement.appendChild(ItemElement);
    }
}

</SCRIPT>

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

Acknowledgements

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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
DiVitas's Mobile UC Now Available on the Latest Devices · Review: FON Fonera 2.0n · Chip Market Recovering From '08 Collapse

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

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