I developed a client side application and unfortunately I suspect memory leaks.
The application has a lot of private clone objects, and at the end of each function I dispose the objects by set them to null. (foo = null;)
My question is, how should I dispose of the objects?
Is it enough to use foo = null?
Also, are there any tools that can help me identify the problem?
SOLUTION
finally my problem caused of a wrong use of the jquery progress bar
function updateProgressBar() {
if (!handle) //by adding this, the problem solved.
return;
jQuery("#progressbar").progressbar({
value: ++pct
});
if (pct >= 100) {
clearInterval(handle);
pct = 0;
setInterval("updateProgressBar()", 300);
}
}
-
2Why do you suspect a memory leak?KTastrophy– KTastrophy2012年03月22日 16:16:05 +00:00Commented Mar 22, 2012 at 16:16
-
I observe the the process of the browser and will I access the application, after a minute or two the memory increasing dramatically and in the end I am getting a message from the browser which says "Low memory". Maybe I use wrong word by "suspected". The correct is that I am sure :)profanis– profanis2012年03月22日 16:20:28 +00:00Commented Mar 22, 2012 at 16:20
-
Check out the chrome developer tools. There's a heap snapshot that will show you how much memory you're consuming at x time and will let you go through your entire chain.Snuffleupagus– Snuffleupagus2012年03月22日 16:21:17 +00:00Commented Mar 22, 2012 at 16:21
-
It would be helpful to know what browsers you're seeing this in.Erik Reppen– Erik Reppen2012年03月22日 16:43:33 +00:00Commented Mar 22, 2012 at 16:43
-
firefox and chrome. Finally was a wrong use of jquery progrssBar(). But through this task, I learn how to identify memory leaks :)profanis– profanis2012年03月22日 18:20:32 +00:00Commented Mar 22, 2012 at 18:20
2 Answers 2
The main reason for memory leaks in a browser is when you have cyclical links between DOM and JavaScript objects. Mostly happens when orphaned DOM nodes still refer to event handlers or other JS objects. http://code.google.com/chrome/devtools/docs/heap-profiling-dom-leaks.html
Chrome developer tools lets you look at the heap and examine elements that are still lying in memory but are not through the "Heap Profiler" used http://gent.ilcore.com/2011/08/finding-memory-leaks.html
But to address the actual answer, setting a property to null is enough to break cyclical references and should fix memory leaks.
3 Comments
May it be a problem with closures? You should try the methods that the current browsers provide, like Speed Tracer for Chrome.
In any case, a snippet of the code you are using would be useful to try to identify the problem.