WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Memory Leaks in Menu4, Micha Schopman, July 1, 2002
     Re:Memory Leaks in Menu4, Erik Arvidsson, July 1, 2002
             Re:Memory Leaks in Menu4, Ed Schiebel, October 25, 2002
                 Re:Memory Leaks in Menu4, Erik Arvidsson, October 27, 2002
                     Re:Memory Leaks in Menu4, Ed Schiebel, October 29, 2002
                         Re:Memory Leaks in Menu4 , Ed Schiebel, October 29, 2002
                             Re:Memory Leaks in Menu4 , Erik Arvidsson, October 29, 2002
                         Re:Memory Leaks in Menu4, Erik Arvidsson, October 29, 2002
                             Re:Memory Leaks in Menu4, Ed Schiebel, October 29, 2002

Subject: Re:Memory Leaks in Menu4 From: Ed Schiebel Date: October 29, 2002

Menubar.prototype.hookupMenu has the following code:

for ( var i = 0; i < l; i++ ) {

items[i]._htmlElement = cs[i];

cs[i]._menuItem = items[i];

}

This creates a circular reference between a jscirpt object and a DHTML DOM object.  Comment out either line in the loop and the leak shrinks.  This seems to be the biggest leak I've found so far.

If you want to watch this happen, add

onload="window.setTimeout('location.reload()', 30, 'javascript')"

to the <body> tag of simpledemo.html.  There is similar code in Menu.prototype.drawMenu.

You may use my name once this gets cleaned up.
--ed

From: Erik Arvidsson
Sent: October 29, 2002
Subject: Re:Memory Leaks in Menu4

Its a bit ugly but if that solves the worst memory leaks I'm willing to use a global cache.

I would use a hash table for the cahce so that items can be removed faster and cleaner. Otherwise it is a sound idea.

Thanks for spending time on this. I'll add your name to the credits if you do not mind?

erik

-------------------------------------------------------

I was able to break all the closures.
create a global array, _globalMenuCache add a new member to MenuBar, Menu and MenuItem, this._ordinal In each object's constructor set this._ordinal = _globalMenuCache.length, then _globalMenuCache[this._ordinal] = this Everywhere a local function is used, call a global instead, and pass in the objects _ordinal value. In the global function set oThis = _globalMenuCache[ordinal] the global function now has access to the object.
I'm still experiencing a significant memory leak though.
--ed


From: Erik Arvidsson
Sent: October 27, 2002
Subject: Re:Memory Leaks in Menu4

It is of course impossible to remove the closures. Closures are what makes JS such a good language. Without closures all objects would need to be global.

However, I'll see if I can break a few of these circular references. I have tried this before and I did not see any improvements. The following features are required.

attachEvent, setTimeout: Both require function expressions to encapsulate local objects.

I have tried detachEvent but that did not help at all.

erik






Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX