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 25, 2002

I'm also seeing a substantial memory leak when using Menu4.  I worked the issue with Microsoft support, and the engineer created a minimal page that exhibits the problem.  Here is the smallest leaking page, and the explanation.

<HTML>     <HEAD>         <script language="javascript">         function refreshData()         {             window.location.reload();         }         function initpage()         {             window.setTimeout("refreshData()", 50, "javascript");         }         </script>     </HEAD>     <body onload="initpage()" >         <div class='menu-bar' id='menubar'></div>         <script language='javascript'> 	hookup(document.getElementById('menubar')); 	function hookup(element) 	{ 	    element.attachEvent( "onmouseover", mouse); 	    function mouse ()  	    { 	    } 	}         </script>     </body> </HTML> 

Once the page is this small it becomes easy to diagnose the circular reference causing the leak.

hookup has a reference to menubar in its activation frame mouse, a closure, has a reference to hookup's activation frame menubar has a reference to mouse.

So now we have the circular reference: menubar -> mouse -> hookup activation frame -> menubar

This is a circular reference which contains a non-Jscript object so the JScript garbage collector cannot detect it. The solution is to stop using closure semantics. Do this:

function h(element)
{
element.attachEvent( "onmouseover", mouse);
}
function mouse () { }

Now mouse is not a closure object so it has no reference to h or m.

This code is analagous to MenuBar.Write(), which calls Menu.hookupElement() (which has some funky looking code in it. The element is passed in as the parameter 'd', but then a local variable d is created as this.document.)  Do you want a crack at fixing this, or should I?

--ed

From: Micha C.A. Schopman
Sent: July 1, 2002
Subject: Re:Memory Leaks in Menu4

The image I showed you consist out of this:

1) framerow
      iframe with the outlookbar
      iframe with the content
(both iframes are aligned horizontal using tables <td>iframe 1</td><td>iframe 2</td>)

2) framerow (now visible, normally invicible)
     containing app engine, which handles all form requests, security etc..

The only time I get memory leaks it is when i include the menu, when left out of the app, MSIE does not show any memoryleaks at all, and releases the memory normally quick after each reload.

Pretty odd, while JScript does not need any type of memory releasing. However I heard a lot complaints about using prototyping with javascript from other people using JScript very much. *bad sentence :p*


 

From: Erik Arvidsson
Sent: July 1, 2002
Subject: Re:Memory Leaks in Menu4

Please do not reload complicated pages in IE. IE does not free any memory when reloaded. If you are creating a web application use iframes that are hidden instead of reloaded.

I'm sorry that IE cannot handle something as crucial as releasing memory when leaving a page. I guess MS does this on purpose to make it harder to create web applications that compete with Windows applications :-)

Maybe there is something that can be done to at least improve the memory issues a little. For example one can walk through all JS objects and make sure that all references to DOM object are removed.

erik

From: Micha Schopman
Sent: July 1, 2002
Subject: Re:Memory Leaks in Menu4

I've included Menu4 2x using <object> and scriptlet type, starting at a usage of 20MB of MSIE 6.* I refreshed a couple of times, and memory usage got a 40MB increase.

When disabling menu4, the memory leaks dissapear.

 







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