Take the 2-minute tour ×

Recently, I came across one of my application which consumes too much memory and increasing by 10 MB/sec.

So, I like to know the best way to destroy javascript object and variables so memory consumption stay down and my FF can't get destroyed.

I am calling two of my javascript in every 8 sec interval without reloading the page.

function refresh() {
    if (refreshTimer) {
        refreshTimer = null ;
    $('<div id="preload_xml"></div>').html('<img src="pic/dataload.gif" alt="loading data" /><h3>Loading Data...</h3>').prependTo($("#td_123"));

How can I see which variable cause Memory overhead and method to stop execution of that process?

share|improve this question
Have you considered isolating portions of your codes using closures ? –  YS. Apr 20 '12 at 12:26
Have you tried anything? Like using obj = null? –  Florian Margaine Apr 20 '12 at 12:27
A) What does show_topology do? --- B) Are you ever clearing out the things you add to #td_123? --- C) Is there a live version of this somewhere? –  Deestan Apr 20 '12 at 12:45

4 Answers 4

up vote 32 down vote accepted

You could put all your code under one namespace like this:

var namespace = {};

namespace.someClassObj = {};

delete namespace.someClassObj;

using the delete keyword will delete the reference to the property, but on the low level the javascript GC will get more information about which objects to be reclaimed.

you could also use chrome to get memory profile of you app, and which objects in you app are need to be scale down.

share|improve this answer
How can u use chrome to get memory profile? –  Amit Shah Apr 20 '12 at 12:42
Press F12 to get developer tools. Go to the Profile tab and Click on Start to start the profile. You can do the profiling on JS CPU, CSS Selector and you can take the Heap snapshot. –  Sarath Apr 20 '12 at 19:01
or in latest chrome type the word performance in the js console –  David Morrow Sep 11 '13 at 18:01

You can't delete objects, they are removed when there are no more references to them. You can delete references with delete.

However, if you have created circular references in your objects you may have to de-couple some things.

share|improve this answer

Structure your code so that all your temporary objects are located inside closures instead of global namespace / global object properties and go out of scope when you've done with them. GC will take care of the rest.

share|improve this answer

I was facing a problem like this, and had the idea of simply changing the innerHTML of the problematic object's children.

adiv.innerHTML = "<div...> the original html that js uses </div>";

Seems dirty, but it saved my life, as it works!

share|improve this answer

Your Answer


