Welcome to WebmasterWorld Guest from 107.20.75.63

Forum Moderators: open

Message Too Old, No Replies

Javascript Memory Leakage

My sitemap/menu may be unusable

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

Full Member

10+ Year Member

joined:Mar 18, 2002
posts:309
votes: 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
}
}
10:34 pm on Aug 26, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 4, 2002
posts:508
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 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

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members