How to fix this window.open memory leak?

Posted by DotnetShadow on Stack Overflow See other posts from Stack Overflow or by DotnetShadow
Published on 2010-05-19T08:34:56Z Indexed on 2010/05/19 8:40 UTC
Read the original article Hit count: 395

Filed under:
|
|

Hi there,

I was recently looking at this memory leak tool sIEve: http://home.orange.nl/jsrosman/

So I decided to test out the tool by creating a main page that will open up a popup window. I started by creating 3 pages: index.html, page1.html and page2.html, the index.html page will open a child window (popup) linking to page1.html. Page1 will have a anchor tag that links to page2.html, while page2 will have a link back to page1.html

PROBLEM

So in the tool I entered the index.html page, popup window opened to page1.html, I then clicked the page2 link, no leaks detected yet.

While I'm on page2 I click the link back to page1, and that's where the tool claims there is a link. The leak seems to be happening on the index.html page and I have no idea as to why it would be doing that. Even more concerning is that I can see elements that the tool detects that aren't even on my page.

Does anyone have any experience with this tool or know if this really is a memory leak? Any samples of showing how to achieve what I'm doing without memory leaks?

INDEX.HTML

  <script type="text/javascript">

   MYLEAK = function() { 
    var childWindow = null;

    function showWindow() {
     childWindow = window.open("page1.html", "myWindow");                 
     return false;
    }         
    return {     
     init: function() {
      $("#window-link").bind("click", showWindow);               
     }      
    }       
   }();   

  </script>

 </head>

<body> 
 <a id="window-link" href="#" on>Open Window</a>

 <script type="text/javascript">   
  $(document).ready(function() {
   MYLEAK.init();   
  });
 </script>

</body>
</html>

PAGE1.HTML

<html>
<body>

 <h1>Page 1</h1>
 <a href="page2.html">Page2</a> 
</body>
</html>

PAGE2.HTML

<html>
<body>
 <h1>Page 2</h1>
 <a href="page1.html">Page1</a> 
</body>
</html>

Appreciate your efforts.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about memory-leaks