4

I am working on an AJAX application with a lot of Javascript. All pages are loaded through AJAX.
On a certain page I have a grid which is build in Javascript. Now when I leave that page I want to destroy that grid. I call jQuery.remove() but this only deletes the object from the DOM.
My question is how can I delete this grid object from the memory? Cause it still exists when I move away from the page.

Much appreciated!

5
  • 2
    How do you know that this object still exists in memory after you navigate away from the page? Commented Feb 25, 2011 at 8:26
  • Do you store grid identifier in variable? If so then make gridVar = null; Commented Feb 25, 2011 at 8:26
  • 1
    It's completely up to the browser... I guess you assume it still exist in memory because the browser process memory usage is not decreasing? Commented Feb 25, 2011 at 8:28
  • When I open the firebug console I can see the object still exists. It's only deleted from the DOM. Commented Feb 25, 2011 at 10:21
  • firebug can't really tell what is in the memory and what isn't in the memory, I would look for more "reliable" tool if you're really into it. Commented Feb 27, 2011 at 8:52

2 Answers 2

7

If you delete all references to your grid (i.e. assign null to the variable), the garbage collector will delete the object from memory.

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

2 Comments

This would work if there is an actual unload event fired but because this is an all ajax app this is not happening.
An option could be to call an unload event everytime you navigate through your ajax application. This isn't a nice solution though..
1

put the grid into a div or anything you want. when you want to delete it use

$("<the name of the div>").empty();

that will clear it.

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.