Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Memory leak caused by javaScript

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my web application, I have a lot of javaScript functions which, as I leaned recently, leak memory because I�m creating closures, but I don�t understand how I can create DHTML without them. For example:


According to the articles I�ve read on the internet (one of them: Memory Leak in IE, IE does not free up the memory for those objects because DOM objects is referencing javaScript object � � and function has the reference to the DOM object, so there is a circular reference.

In all the articles that I�ve read I can�t quite understand/find the solution to this problem. I think I saw a suggestion of declaring the function in the global scope and then assigning it to the element.onclick property, but doesn�t it still create a circular reference?

Can any one point me to the working solution?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you actually seeing memory leaks in your application?

http://home.wanadoo.nl/jsrosman/

Little article from MS on leaks: http://msdn2.microsoft.com/en-us/library/bb250448.aspx

Eric
 
Tatyana Chinya
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric,

I did see the memory leak first using Task Manager and I also tried Drip, but Drip was crashing on pop-up windows, but it also reported memory leak.

The article that you linked is the same one that I referred to in my post. As I understand, it suggests to use expandoProperty, which I don't know much about and not sure if it works for FF and Mozilla.

Is using expandoProperty the only way to solve the problem?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoops I posted the wrong link: http://www.codeproject.com/KB/scripting/leakpatterns.aspx

There are a few links at the bottom of the long article with ideas on solutions.

Eric
 
Tatyana Chinya
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric,

I've read that article before, and it looks like most of the content is copied from the msdn.microsoft article. I don't think I've checked the links on the bottom before. Two of them don't work, but the other two have some code, so I will look at that.

One more questions: Did you ever use sIEve? I downloaded the exe and started playing with it, but I can't figure out how to know which line of code has an issue. When I click on "Show leaks", the first column shows the number, so I thought it may be the line number in code. But when I go to that line, there is no tag that the Tag column is referring to.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic