Welcome to WebmasterWorld Guest from 54.167.0.111

Forum Moderators: open

Message Too Old, No Replies

Javascript Memory Leakage

My sitemap/menu may be unusable

     

olwen

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

10+ Year Member



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

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



// 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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month