Avoiding jqPlot Memory Leaks
by edsilverton
I’ve run into some problems when re-plotting data in jqPlot where it’s creating huge memory leaks.
To get around this I’ve put my charts into a container div and when re-plotting I use:
$(‘.jqPlot’).remove();
which clears the charts from memory entirely.
I then recreate the chart divs like so:
$(‘#plotContainer’).append(‘<div class=”jqPlot” id=”targetPlot” style=”height:320px; width:600px;”></div>’);
$(‘#plotContainer’).append(‘<div class=”jqPlot” id=”controllerPlot” style=”margin-top: 30px; height:100px; width:600px;”></div>’);
and re-initialize the plots with their new data:
targetPlot = $.jqplot(‘targetPlot’, [data], {
Seems to do the trick
Advertisement
Hi,
I tried the mentioned approach and still the memory leaks.
It looks remove() or empty() doesn’t help. The generated plot is still in the memory creating the problems.
Could you please reconfirm on the approach.
Thanks
Sabari
I’ve been using this approach successfully. I haven’t tested it with a memory profiler or anything. Before I implemented this the browser would noticeably hang more every time I added a new plot. Now I can re-plot indefinitely without an issue. Just to be clear, I’m entirely removing the div that’s used by jqPlot and programmatically recreating it when I want a new plot.
Thanks for your response,
I even tried to remove the div entirely and then created the div programtically.
It looks there is still a leak and verified in drip tool. Somehow the plot is still in the memory even after reload of page..
i even tried some steps from http://groups.google.com/group/jqplot-users/tree/browse_frm/month/2011-02/10a2fac0bf99491f?rnum=11&lnk=nl
but without luck,,now i am thinking on the plot usage… do u have any other ideas on the memory leak..it would be helpful.
Thanks
Are you only having the problem in IE? I need to do testing in IE so it’s possible I’ll have the same problem. My hunch if it’s IE-specific is that there’s a problem with the excanvas script that jqPlot uses to provide IE with canvas support. Maybe there’s a way to nullify all vars created by excanvas?
test
this is a test
Hi all,
I think, you should destroy the object targetPlot = $.jqplot(‘targetPlot’, [data], options) by var also, in order to remove memory for the object too.
Hello,
you should use the “destroy” method (plot.destroy()) on your plot before you empty the container and draw the plot again.
It worked for me!