5

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!

Gerard
  • 1,829
  • 5
  • 16
  • 20

2 Answers2

6

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

krtek
  • 26,334
  • 5
  • 56
  • 84
  • 1
    This would work if there is an actual unload event fired but because this is an all ajax app this is not happening. – Gerard Feb 25 '11 at 10:22
  • An option could be to call an unload event everytime you navigate through your ajax application. This isn't a nice solution though.. – Rob Feb 25 '11 at 10:37
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.

Hoy Cheung
  • 1,552
  • 3
  • 19
  • 36