以一种清理所有事件处理程序而不会导致内存泄漏的方式销毁jQuery flot图的正确方法是什么?
似乎flot留下了一些僵尸(又名Detached Dom Trees)
答案 0 :(得分:7)
如果您阅读了API文档,那么有一种可以清理的关闭方法
shutdown()
Cleans up any event handlers Flot has currently registered. This
is used internally.
例如
var plot = $.plot($("#yourDiv"), options)
plot.shutdown()
答案 1 :(得分:4)
对于将来来这里的人,现在有一个destroy
函数调用shutdown并删除canvas元素。由于某种原因,它在API中没有记录,但可以在代码中找到:
var flot = $("#FlotDiv").data('plot')
if (flot) // If it's destroyed, then data('plot') will be undefined
flot.destroy();
答案 2 :(得分:3)
如果要删除事件处理程序,请尝试使用jquery off
方法。
用于清除flot图。你可以清空div。
$('#yourFlotDiv').empty();
答案 3 :(得分:0)
删除flot Graph
var placeholder = $("#FlotDiv");
placeholder.unbind(); //Remove a previously-attached event handler from the elements.
placeholder.empty();
如果您希望取消绑定特定事件,这是可行的方法:
$( "#foo").unbind( "click" );
有关详情,请查看this。