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 :-)

About these ads