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!
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.
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.
The delete operator removes a given property from an object. On successful deletion, it will return true , else false will be returned.
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.
If you delete all references to your grid (i.e. assign null to the variable), the garbage collector will delete the object from memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With