How do I delete a chart object from memory?
« Back to message list
Hi I'm creating a kind of widget application in which the user drags an image to a div and it creates a inner div in the
destination div with the canvas element for the graph.
I hold a variable for each graph type in the widget options to delete that created graph i have a method that does the following.
RGraph.ObjectRegistry.Remove(window[graphObjName]);
Then I set the graph object to null and finally I delete with jQuery the div that was created for the graph element with the empty method.
Doing this gets rid of the dom element and the graph but if i do a heap profile it shows me the Rgraph.Pie object is still in the memory.
Is there any way to delete that graph object in a correct way to prevent memory leaks?
Thanks in advance.
Posted by RGraph support on 28th November 2013I hold a variable for each graph type in the widget options to delete that created graph i have a method that does the following.
RGraph.ObjectRegistry.Remove(window[graphObjName]);
Then I set the graph object to null and finally I delete with jQuery the div that was created for the graph element with the empty method.
Doing this gets rid of the dom element and the graph but if i do a heap profile it shows me the Rgraph.Pie object is still in the memory.
Is there any way to delete that graph object in a correct way to prevent memory leaks?
Thanks in advance.
Hi there,
The only other reference to the object that I can think of is the canvas.__object__ reference - which pre-dates the ObjectRegistry. So before removing the canvas you could set that to null.
Of course if you have any other references to the chart object they will need removing too.
Richard, RGraph Support
Posted by Eduardo Quintana on 29th November 2013The only other reference to the object that I can think of is the canvas.__object__ reference - which pre-dates the ObjectRegistry. So before removing the canvas you could set that to null.
Of course if you have any other references to the chart object they will need removing too.
Richard, RGraph Support
Hello again,
I tried what you proposed but i got the same result the thing i tried the following:
for(var prop in pie){
pie[prop] = null;
delete pie[prop];
}
RGraph.ObjectRegistry.Remove(pie);
pie= null;
Then I call the jQuery empty method to the div containing all the graph stuff.
Doing this reduces greatly the amount of space that the object occupies in memory after being deleted, but it holds only one property now it is the properties property.
This is an example of the retained object in memory
Rgraph.Pie
>Rgraph.Pie
properties :: (object properties)
>__proto__
Any ideas?
Thank you in advance for your help.
Posted by RGraph support on 29th November 2013I tried what you proposed but i got the same result the thing i tried the following:
for(var prop in pie){
pie[prop] = null;
delete pie[prop];
}
RGraph.ObjectRegistry.Remove(pie);
pie= null;
Then I call the jQuery empty method to the div containing all the graph stuff.
Doing this reduces greatly the amount of space that the object occupies in memory after being deleted, but it holds only one property now it is the properties property.
This is an example of the retained object in memory
Rgraph.Pie
>Rgraph.Pie
properties :: (object properties)
>__proto__
Any ideas?
Thank you in advance for your help.
Hi there,
No - but if all you have left is a shell of an object then it won't be occupying a great deal of memory. If you have a long running chart - then instead of creating a new chart each update you can update the data property of a single object - like this chart does (it also makes careful use of local instead of global variables):
www.rgraph.net/demos/line-dynamic-updates.html
Richard, RGraph Support
No - but if all you have left is a shell of an object then it won't be occupying a great deal of memory. If you have a long running chart - then instead of creating a new chart each update you can update the data property of a single object - like this chart does (it also makes careful use of local instead of global variables):
www.rgraph.net/demos/line-dynamic-updates.html
Richard, RGraph Support
Add a reply
« Back to message list