Recently, I came across one of my application which consumes too much memory and increasing by 10 MB/sec.
So, I like to know how to destroy JavaScript object and variables so memory consumption stays down and my FF can't get destroyed.
I am calling two of my scripts every 8 seconds without reloading the page.
function refresh() { $('#table_info').remove(); $('#table').hide(); if (refreshTimer) { clearTimeout(refreshTimer); refreshTimer = null ; } document.getElementById('refresh_topology').disabled=true; $('<div id="preload_xml"></div>').html('<img src="pic/dataload.gif" alt="loading data" /><h3>Loading Data...</h3>').prependTo($("#td_123")); $("#topo").hide(); $('#root').remove(); show_topology(); }
How can I see which variable cause Memory overhead, what's the method to stop the execution of that process?
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.
instance = new Class(); //since 'storage. instance' is your only reference to the object, whenever you wanted to destroy do this: storage. instance = null; // OR delete storage.
To "destroy" a function in javascript, simply ensure that the function becomes unreachable. This will enable the function to be eligible for reclamation.
The object destructuring is a useful JavaScript feature to extract properties from objects and bind them to variables. What's better, object destructuring can extract multiple properties in one statement, can access properties from nested objects, and can set a default value if the property doesn't exist.
You could put all of your code under one namespace like this:
var namespace = {}; namespace.someClassObj = {}; delete namespace.someClassObj;
Using the delete
keyword will delete the reference to the property, but on the low level the JavaScript garbage collector (GC) will get more information about which objects to be reclaimed.
You could also use Chrome Developer Tools to get a memory profile of your app, and which objects in your app are needing to be scaled down.
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