3

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);
        }
    }
5
  • 2
    Why do you suspect a memory leak? Commented 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 :) Commented 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. Commented Mar 22, 2012 at 16:21
  • It would be helpful to know what browsers you're seeing this in. Commented 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 :) Commented Mar 22, 2012 at 18:20

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

the second url you suggested me is great. Thanks a lot
Unfortunately, the second link refers to a user with a Mac. Anything a user does with a Mac should be discarded. Silly Mac, tricks are for kids. </silly>
@ShadowScripter Didn't get your humor :p
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.