LoginSignup
1
1

More than 5 years have passed since last update.

jqPlotでブラウザが落ちる場合の対応

Posted at

jqPlotでグラフを描画しています。
セレクトボックスの値が切り替わったら、グラフを再描画しています。
セレクトボックスを数回変更したら、ブラウザが落ちてしまいました。

原因はメモリリークのようで、destroyメソッドを実行したら解決しました。

コード

document.getElementById("selectbox").onchange = drawChart;

function drawChart() {
 //グラフ描画処理
 $.jqPlot("chartArea", ...);
};
var chartObject; //グラフオブジェクト(グローバル変数)
document.getElementById("selectbox").onchange = drawChart;

function drawChart() {
 if (chartObject != null) {
   chartObject.destroy();
 }
 //グラフ描画処理
 chartObject = $.jqPlot("chartArea", ...);
};

参考サイト

http://www.jqplot.com/docs/files/jqplot-core-js.html#jqPlot.destroy
http://stackoverflow.com/questions/6380016/what-to-do-with-jqplot-memory-leak

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1