Memory leak in flotr2?

156 views
Skip to first unread message

Jochen Berger

unread,
Aug 1, 2011, 5:13:23 AM8/1/11
to fl...@googlegroups.com
Hi,

I encounter a memory leak when repainting the same graph multiple times.
I observed the same behavior using firefox 5 and chromium 12 together
with the current flotr2 HEAD (r300).
I've uploaded a minimalistic sample page (http://ul.to/76y635ah).
Basically, when clicking the link, it a chart of y=x^2 with 1000
x-values is recreated 100 times.
In Firefox 5, each time the link is clicked, the process' memory
consumption increases by about 25MB.
Unfortunately I haven't found a solution yet, but I suspect closures
over DOM elements in event handlers or the like.
Also, the global variables i, p and type get assigned during the
creation of the graph, but I don't think that this is related to the
memory issues.
Maybe someone has an idea how to debug this kind of problem so I might
be able to come up with a fix?

Regards,
Jochen

George

unread,
Aug 1, 2011, 10:28:45 AM8/1/11
to fl...@googlegroups.com
Is there a flotr2?

Memory leak issues are common in flot and flotr. They all have
solutions. I suggest you search through this google group and
also the flot google group for memory leak issues. The code for
flot and flotr are very similar.

So one thing I found with flotr is if I changed the line that does
the graph from:
var plot=...
to
...

It fixed my main memory leak.

Also when you are getting down to fixing the last little bit of a
leak you might find it is simply firebug which stores all the ajax
data for viewing purposes.

People fixed many leaks by doing some unbinding.

In flotr if you bind mouse events to a plot you might only want to
bind them once (the first time you do the plot) but not the
remaining thousands of times.

flot has a method of redrawing the graph. I don't know if flotr
has this same method. But the method is tricky - you have to call
about 4 functions if I remember right but the functions are very
simple to call - I think most have zero parameters. This seems to
work for the most amount of people.

ie 7 (I think it's 7) has horrendous memory leak issues not seen
in other versions that are fixed by using a newer version of the
canvas library thing (excanvas? I forget what it's called).

- George

On Mon Aug 01 04:13:23 CDT 2011, Jochen Berger
<foob...@googlemail.com> wrote:

> -- You received this message because you are subscribed to the
> Google Groups "Flotr Javascript Plotting Library" group.
> To post to this group, send email to fl...@googlegroups.com.
> To unsubscribe from this group, send email to
> flotr+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/flotr?hl=en.
>
>

Jochen Berger

unread,
Aug 1, 2011, 10:49:16 AM8/1/11
to fl...@googlegroups.com
George,

thanks for your response, though I wished you'd had taken a look at my
sample before writing it. ;-)

Am Montag, den 01.08.2011, 09:28 -0500 schrieb George:
> Is there a flotr2?

Yes, there is a flotr2 branch in the SVN:
http://code.google.com/p/flotr/source/browse/#svn%2Fbranches%2Fflotr2
AFAICT, there has neither been an official announcement nor a release
yet.

> Memory leak issues are common in flot and flotr. They all have
> solutions. I suggest you search through this google group and
> also the flot google group for memory leak issues. The code for
> flot and flotr are very similar.

Ok, I'll have a look into the flot archives then.

Unfortunately, the other cases you mention don't really apply to my
example; neither do I do any AJAX updates nor do I bind event listeners
in my own code, nor do I assign the Graph object to a variable, nor do I
use IE7/excanvas, although I do most of that in the project that has
brought me across these leaks in the first place. ;-) But as I can also
reproduce the problem without those potential causes for leaks, I think
it has nothing to do with them.

Thanks,
Jochen


George

unread,
Aug 1, 2011, 6:38:14 PM8/1/11
to fl...@googlegroups.com
> nor do I bind event listeners

Are you sure? You can't have any mouse related activities such as
tooltips on graph points unless there is some kind of mouse event
binding. Maybe this isn't obvious how to unbind though.

Although 25MB memory leak per graph sounds like something other
than mouse event binding.

- George

Jochen Berger

unread,
Aug 2, 2011, 2:26:25 AM8/2/11
to fl...@googlegroups.com
Hi,

Am Montag, den 01.08.2011, 17:38 -0500 schrieb George:

> > nor do I bind event listeners
>
> Are you sure?

Quite. I said that I don't bind any event listeners *in my own code*. Of
course flotr oberseves events like mouseover, mouseout and click
underneath. I really suggest you have a look at my sample.

Btw, I found this issue in the flot tracker yesterday. I'm not sure but
maybe it is related.
http://code.google.com/p/flot/issues/detail?id=269

Jochen

Reply all
Reply to author
Forward
0 new messages