Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroying jQuery Flot Graph

Tags:

jquery

flot

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)

like image 201
thecountofzero Avatar asked Apr 07 '13 01:04

thecountofzero


3 Answers

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()
like image 157
DaveB Avatar answered Nov 14 '22 23:11

DaveB


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();
like image 4
bradlis7 Avatar answered Nov 14 '22 23:11

bradlis7


if you want to remove event handlers then try jquery off method.

for to clear flot graph. you can empty the div.

$('#yourFlotDiv').empty();
like image 3
Ravi Gadag Avatar answered Nov 14 '22 23:11

Ravi Gadag