spacer

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


home / experts / dhtml / column59

Developer News
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next
Logo

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



Since only IE5+ is affected by the memory problem, the only file that we have changed in HM4.1.1 is HM_ScriptDOM.js.

Tracking the Variables

Early in the script, we initialize an empty array to store all the relevant JS variables that we will create later, and create a function that will store any variable passed to it in the array.

if(HM_IE) {
    HM_a_ElementsCreated = [];

    function HM_f_StoreElement(el){
        HM_a_ElementsCreated[HM_a_ElementsCreated.length] = el;
    }
}

In the HM_f_MakeElement() function, where all menu elements are created, we add a single statement that stores the menu element in our array:

function HM_f_MakeElement(menuid) {
    var MenuObject;
    MenuObject = document.createElement("DIV");

    if(HM_IE)HM_f_StoreElement(MenuObject);
    ...
}

In the HM_f_MakeItemElement() function, where all item elements are created, we add similar statements to store the item element and any contained "more" image element:

function HM_f_MakeItemElement(menucount) {
    var ItemElement = document.createElement("DIV");

    if(HM_IE)HM_f_StoreElement(ItemElement);
    ...
    if(ItemElement.hasImage) {
        var ImageElement = document.createElement("IMG");

        if(HM_IE)HM_f_StoreElement(ImageElement);
        ...
    }
    ...
}

Freeing Memory

At the end of our script, we place an onunload handler for IE users. If there is already an onunload handler assigned to the page, it is stored in HM_f_OtherOnUnload, in the same way that we store already assigned onload and onresize handlers.

When the user leaves the page, all JS variables that refer to elements are set to null. Then we cycle through the HM_a_ElementsCreated array, and set all properties of each element that refer to other elements to null. Finally any properties of the menu tree object are nulled.

Once this is done, any other onunload handler is executed by calling HM_f_OtherOnUnload().

if(HM_IE) {
    HM_f_OtherOnUnload = (window.onunload) ? window.onunload :  new Function;
    window.onunload = function(){
        HM_CurrentMenu = null;
        HM_CurrentItem = null;
        HM_CurrentTree.treeParent = null;
        HM_CurrentTree.startChild = null;

        var Eclength = HM_a_ElementsCreated.length;
        for(var i=Eclength-1; i>=0; i--){
            TempElement = HM_a_ElementsCreated[i];
            TempElement.parentMenu = null;
            TempElement.parentItem = null;
            TempElement.itemElement = null;
            TempElement.currentItem = null;
            TempElement.child = null;
            TempElement.siblingBelow = null;
            TempElement.imgLyr = null;
        }
        TempElement = null;

        for(var i=0; i<HM_TotalTrees; i++) {
            HM_a_TopMenus[i].tree.startChild = null;
            HM_a_TopMenus[i].tree.treeParent = null;
        }

        HM_f_OtherOnUnload();
    }
}

Files Changed in Version 4.1.1

You will need to overwrite previous versions of the above file to upgrade to 4.1.1.



On the next page, the sample page included in the download.


Produced by Peter Belesis and



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview · Controllers: Programming Application Logic - Part 2 · How to Use JavaScript to Validate Form Data
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Choosing the Right Online Backup Provider · Mother Avaya Nurtures Her Technology Partners · Software as a Service a Winning Model for Hotspot Provider

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

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