homepage Welcome to WebmasterWorld Guest from 54.204.67.26
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript Memory Leakage
My sitemap/menu may be unusable
olwen




msg:1486042
 10:07 pm on Aug 26, 2003 (gmt 0)

For our company intranet I'm looking at a sitemap as a series of nested ULs. Up to 4 levels deep. I've used CSS to style and hide them.
A mouseover on LI tags calls menutoggle to reveal the lower braches be altering visibilty of the UL tag and alters the appearance of the LI tag. Especially with larger branches there appears to be increased memory use at each change. Can anyone spot anything in my Javascript I could add/remove to prevent memory leakage?
menuhide=new Array()
prevmenu=new Array('','','','','')
function menutoggle(menu,level) {
if (document.getElementById('s' + menu)) {
show= document.getElementById('s' + menu).style.display
if (prevmenu[level]!="") {
document.getElementById('s' + prevmenu[level]).style.display="none"
document.getElementById('m' + prevmenu[level]).style.backgroundImage='url("blue.jpg")'
}
document.getElementById('s' + menu).style.display="block"
document.getElementById('m' + menu).style.backgroundImage='url("red.jpg")'
prevmenu[level]=menu
}
}

 

garann




msg:1486043
 10:34 pm on Aug 26, 2003 (gmt 0)

I see two things you could clean up, though I doubt either is causing your problem..

1. It doesn't appear you ever use this variable show:
show= document.getElementById('s' + menu).style.display
If so, you could delete that line.

2. You could put the string (?) prevmenu[level] into a variable, so you don't have to look it up each time.

Good luck..
g.

MonkeeSage




msg:1486044
 3:26 am on Aug 27, 2003 (gmt 0)

// the array length can be undefined on construction,
// if you want to specify a length use a number,
// e.g., Array(4)
prevmenu=new Array();
function menutoggle(menu,level) {
if (document.getElementById('s' + menu)) {
var shown=document.getElementById('s' + menu).style;
if (shown.display!= "none") {
shown.display="none";
// no need to set the image since you are hiding it
}
else {
shown.backgroundImage='url("red.jpg")';
shown.display="block";
}
prevmenu[level]=menu;
}
}

If that still doesn't help, you can sticky me the URL and I'll see if I can spot anything else in the code that might be causing excess memory usage. Fours eyes are better than two. :)

Jordan

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved