Gerard
Gerard

Reputation: 1859

Delete object from memory in javascript

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!

Upvotes: 5

Views: 12047

Answers (2)

Hoy Cheung
Hoy Cheung

Reputation: 1670

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.

Upvotes: 1

krtek
krtek

Reputation: 26597

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

Upvotes: 7

Related Questions