What is the correct way to destroy a jQuery flot graph in a way that will clean up all event handlers and not result in a memory leak?
It seems flot is leaving behind some zombies (aka Detached Dom Trees)
If you read the API docs, there is a shutdown method that cleans up for you
shutdown()
Cleans up any event handlers Flot has currently registered. This
is used internally.
eg.
var plot = $.plot($("#yourDiv"), options)
plot.shutdown()
For people who come here in the future, there is now a destroy
function that calls shutdown and removes the canvas element. It's undocumented in the API for some reason, but is available in the code:
var flot = $("#FlotDiv").data('plot')
if (flot) // If it's destroyed, then data('plot') will be undefined
flot.destroy();
if you want to remove event handlers then try jquery off
method.
for to clear flot graph. you can empty the div.
$('#yourFlotDiv').empty();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With