Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 488
Gerard Avatar asked Feb 25 '11 08:02

Gerard


People also ask

Can you delete an object in JavaScript?

Delete object propertiesThe only way to fully remove the properties of an object in JavaScript is by using delete operator. If the property which you're trying to delete doesn't exist, delete won't have any effect and can return true.

How do you clear an object in JavaScript?

Use a for..in loop to clear an object and delete all its properties. The loop will iterate over all the enumerable properties in the object. On each iteration, use the delete operator to delete the current property.

What is delete in JavaScript?

The delete operator removes a given property from an object. On successful deletion, it will return true , else false will be returned.

How do I delete an object in TypeScript?

To remove a property from an object in TypeScript, mark the property as optional on the type and use the delete operator. You can only remove properties that have been marked optional from an object.


1 Answers

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

like image 54
krtek Avatar answered Sep 28 '22 00:09

krtek