Problem of memory leak using FigureCanvasTkAgg

Hello,

I'm PhD student in Bioinformatic and I'm working on a project using matplotlib and Tkinter but I've got a big problem of memory leak using these modules. I'll be very grateful if you could help me to solve this problem. Here is the link explaining what happends, with a reduced script:
http://stackoverflow.com/questions/43097378/matplotlib-vs-tkinter-memory-leak-using-figurecanvastkagg

Thank you in advance,

Sincerly,

Pierre Garcia, PhD Student

···

---------
Bases Mol?culaires et Structurales des Syst?mes infectieux-UMR5086
Institut de Biologie et Chimie des Prot?ines
7 passage du Vercors
69 367 Lyon cedex 07
---------
Laboratoire de Biom?trie et Biologie Evolutive-UMR5558
UCBL Lyon 1 -B?t. Gr?gory Mendel
43 bd du 11 novembre 1918
69622 VILLEURBANNE cedex

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170511/a65f4fb9/attachment-0001.html>

It is likely there things are not being garbage collected due to either a
missed reference surviving or the circular references between the various
objects is delaying gc from collecting them (I do not recall the details
exactly off the top of my head, but running gc manually with more
generations may help).

However, if you are embedding in a GUI you are probably better off just
doing the embedding directly (and skipping `pyplot` entirely, see
https://matplotlib.org/examples/user_interfaces/embedding_in_tk.html ).
Re-using the Figures / Axes / Artists to update the data (rather than
starting from scratch every time) may also prevent the memory leaks _and_
give you a performance boost.

Please subscribe to the list so that you can post without moderation.

Tom

···

On Sat, Aug 5, 2017 at 12:36 PM GARCIA PIERRE SIMON p0904379 < pierre.garcia at etu.univ-lyon1.fr> wrote:

Hello,

I'm PhD student in Bioinformatic and I'm working on a project using
matplotlib and Tkinter but I've got a big problem of memory leak using
these modules. I'll be very grateful if you could help me to solve this
problem. Here is the link explaining what happends, with a reduced script:

http://stackoverflow.com/questions/43097378/matplotlib-vs-tkinter-memory-leak-using-figurecanvastkagg

Thank you in advance,

Sincerly,

Pierre Garcia, PhD Student
---------
Bases Mol?culaires et Structurales des Syst?mes infectieux-UMR5086
Institut de Biologie et Chimie des Prot?ines
7 passage du Vercors
69 367 Lyon cedex 07
---------
Laboratoire de Biom?trie et Biologie Evolutive-UMR5558
UCBL Lyon 1 -B?t. Gr?gory Mendel
43 bd du 11 novembre 1918
69622 VILLEURBANNE cedex

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170805/57063920/attachment.html>

The stackoverflow posting notes that mpl v1.1.1 was used, which is 5 years
old. I am pretty sure we have made a lot of memory leak fixes since then. I
noted as such on SO.

Ben Root

···

On Sat, Aug 5, 2017 at 7:48 PM, Thomas Caswell <tcaswell at gmail.com> wrote:

It is likely there things are not being garbage collected due to either a
missed reference surviving or the circular references between the various
objects is delaying gc from collecting them (I do not recall the details
exactly off the top of my head, but running gc manually with more
generations may help).

However, if you are embedding in a GUI you are probably better off just
doing the embedding directly (and skipping `pyplot` entirely, see
https://matplotlib.org/examples/user_interfaces/embedding_in_tk.html ).
Re-using the Figures / Axes / Artists to update the data (rather than
starting from scratch every time) may also prevent the memory leaks _and_
give you a performance boost.

Please subscribe to the list so that you can post without moderation.

Tom

On Sat, Aug 5, 2017 at 12:36 PM GARCIA PIERRE SIMON p0904379 < > pierre.garcia at etu.univ-lyon1.fr> wrote:

Hello,

I'm PhD student in Bioinformatic and I'm working on a project using
matplotlib and Tkinter but I've got a big problem of memory leak using
these modules. I'll be very grateful if you could help me to solve this
problem. Here is the link explaining what happends, with a reduced script:
http://stackoverflow.com/questions/43097378/matplotlib-
vs-tkinter-memory-leak-using-figurecanvastkagg

Thank you in advance,

Sincerly,

Pierre Garcia, PhD Student
---------
Bases Mol?culaires et Structurales des Syst?mes infectieux-UMR5086
Institut de Biologie et Chimie des Prot?ines
7 passage du Vercors
69 367 Lyon cedex 07
---------
Laboratoire de Biom?trie et Biologie Evolutive-UMR5558
UCBL Lyon 1 -B?t. Gr?gory Mendel
43 bd du 11 novembre 1918
69622 VILLEURBANNE cedex

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170807/678ce417/attachment.html>

Did the rate of memory leak change?

···

On Thu, Oct 19, 2017 at 10:26 AM, GARCIA PIERRE SIMON p0904379 < pierre.garcia at etu.univ-lyon1.fr> wrote:

Thank you for your answer but I updated MPL to 2.1.0 and the memory leak
is still there. Also, I skipped entirely pyplot and the result is strictly
the same.

Pierre
------------------------------
*De :* Benjamin Root <ben.v.root at gmail.com>
*Envoy? :* lundi 7 ao?t 2017 19:27
*? :* Thomas Caswell
*Cc :* GARCIA PIERRE SIMON p0904379; matplotlib-users at python.org
*Objet :* Re: [Matplotlib-users] Problem of memory leak using
FigureCanvasTkAgg

The stackoverflow posting notes that mpl v1.1.1 was used, which is 5 years
old. I am pretty sure we have made a lot of memory leak fixes since then. I
noted as such on SO.

Ben Root

On Sat, Aug 5, 2017 at 7:48 PM, Thomas Caswell <tcaswell at gmail.com> wrote:

It is likely there things are not being garbage collected due to either a
missed reference surviving or the circular references between the various
objects is delaying gc from collecting them (I do not recall the details
exactly off the top of my head, but running gc manually with more
generations may help).

However, if you are embedding in a GUI you are probably better off just
doing the embedding directly (and skipping `pyplot` entirely, see
https://matplotlib.org/examples/user_interfaces/embedding_in_tk.html ).
Re-using the Figures / Axes / Artists to update the data (rather than
starting from scratch every time) may also prevent the memory leaks _and_
give you a performance boost.

Please subscribe to the list so that you can post without moderation.

Tom

On Sat, Aug 5, 2017 at 12:36 PM GARCIA PIERRE SIMON p0904379 < >> pierre.garcia at etu.univ-lyon1.fr> wrote:

Hello,

I'm PhD student in Bioinformatic and I'm working on a project using
matplotlib and Tkinter but I've got a big problem of memory leak using
these modules. I'll be very grateful if you could help me to solve this
problem. Here is the link explaining what happends, with a reduced script:
http://stackoverflow.com/questions/43097378/matplotlib-vs-
tkinter-memory-leak-using-figurecanvastkagg

Thank you in advance,

Sincerly,

Pierre Garcia, PhD Student
---------
Bases Mol?culaires et Structurales des Syst?mes infectieux-UMR5086
Institut de Biologie et Chimie des Prot?ines
7 passage du Vercors
<https://maps.google.com/?q=7+passage+du+Vercors&entry=gmail&source=g>
69 367 Lyon cedex 07
---------
Laboratoire de Biom?trie et Biologie Evolutive-UMR5558
UCBL Lyon 1 -B?t. Gr?gory Mendel
43 bd du 11 novembre 1918
<https://maps.google.com/?q=43+bd+du+11+novembre+1918&entry=gmail&source=g>
69622 VILLEURBANNE cedex

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171019/cdc40a16/attachment.html>

Have you tried manually adding calls to `gc.collect(2)`? That may help to
clean up any circular reference cycles hanging around.

Can you replicate this with a simpler script? The code on SO is hard to
follow.

Tom

···

On Thu, Oct 19, 2017 at 10:56 AM GARCIA PIERRE SIMON p0904379 < pierre.garcia at etu.univ-lyon1.fr> wrote:

Here is the diagnostic for the old version :

Memory usage: 39832 (kb) Memory usage: 45376 (kb)Memory usage: 46168 (kb) Memory usage: 46960 (kb)Memory usage: 47224 (kb) Memory usage: 47752 (kb)Memory usage: 47752 (kb) Memory usage: 48544 (kb)Memory usage: 48544 (kb) Memory usage: 48808 (kb)Memory usage: 48808 (kb) Memory usage: 49072 (kb)Memory usage: 49072 (kb) Memory usage: 49336 (kb)Memory usage: 49336 (kb) Memory usage: 49864 (kb)Memory usage: 49864 (kb) Memory usage: 50128 (kb)Memory usage: 50128 (kb) Memory usage: 50392 (kb)Memory usage: 50392 (kb) Memory usage: 50656 (kb)

and here is the diagnostic for 2.1.0:

Memory usage: 51808 (kb) Memory usage: 55504 (kb)
Memory usage: 57088 (kb) Memory usage: 57352 (kb)
Memory usage: 57880 (kb) Memory usage: 58144 (kb)
Memory usage: 58672 (kb) Memory usage: 58936 (kb)
Memory usage: 59464 (kb) Memory usage: 59464 (kb)
Memory usage: 59992 (kb) Memory usage: 60256 (kb)
Memory usage: 60520 (kb) Memory usage: 61048 (kb)
Memory usage: 61312 (kb) Memory usage: 61576 (kb)
Memory usage: 62104 (kb) Memory usage: 62368 (kb)
Memory usage: 62632 (kb) Memory usage: 63160 (kb)
Memory usage: 63424 (kb) Memory usage: 63688 (kb)
Memory usage: 64216 (kb) Memory usage: 64480 (kb)

It seems that the initial memory used is higher for 2.1.0.

For the delta against n and n+1, the value varies at the begin
and converge to 264 for 1.1.1 and 792 for 2.1.0.

So globally, the rate of leak increases in 2.1.0....

Pierre
------------------------------
*De :* Benjamin Root <ben.v.root at gmail.com>
*Envoy? :* jeudi 19 octobre 2017 16:32
*? :* GARCIA PIERRE SIMON p0904379
*Cc :* Thomas Caswell; matplotlib-users at python.org

*Objet :* Re: [Matplotlib-users] Problem of memory leak using
FigureCanvasTkAgg
Did the rate of memory leak change?

On Thu, Oct 19, 2017 at 10:26 AM, GARCIA PIERRE SIMON p0904379 < > pierre.garcia at etu.univ-lyon1.fr> wrote:

Thank you for your answer but I updated MPL to 2.1.0 and the memory leak
is still there. Also, I skipped entirely pyplot and the result is strictly
the same.

Pierre
------------------------------
*De :* Benjamin Root <ben.v.root at gmail.com>
*Envoy? :* lundi 7 ao?t 2017 19:27
*? :* Thomas Caswell
*Cc :* GARCIA PIERRE SIMON p0904379; matplotlib-users at python.org
*Objet :* Re: [Matplotlib-users] Problem of memory leak using
FigureCanvasTkAgg

The stackoverflow posting notes that mpl v1.1.1 was used, which is 5
years old. I am pretty sure we have made a lot of memory leak fixes since
then. I noted as such on SO.

Ben Root

On Sat, Aug 5, 2017 at 7:48 PM, Thomas Caswell <tcaswell at gmail.com> >> wrote:

It is likely there things are not being garbage collected due to either
a missed reference surviving or the circular references between the various
objects is delaying gc from collecting them (I do not recall the details
exactly off the top of my head, but running gc manually with more
generations may help).

However, if you are embedding in a GUI you are probably better off just
doing the embedding directly (and skipping `pyplot` entirely, see
https://matplotlib.org/examples/user_interfaces/embedding_in_tk.html ).
Re-using the Figures / Axes / Artists to update the data (rather than
starting from scratch every time) may also prevent the memory leaks _and_
give you a performance boost.

Please subscribe to the list so that you can post without moderation.

Tom

On Sat, Aug 5, 2017 at 12:36 PM GARCIA PIERRE SIMON p0904379 < >>> pierre.garcia at etu.univ-lyon1.fr> wrote:

Hello,

I'm PhD student in Bioinformatic and I'm working on a project using
matplotlib and Tkinter but I've got a big problem of memory leak using
these modules. I'll be very grateful if you could help me to solve this
problem. Here is the link explaining what happends, with a reduced script:

http://stackoverflow.com/questions/43097378/matplotlib-vs-tkinter-memory-leak-using-figurecanvastkagg

Thank you in advance,

Sincerly,

Pierre Garcia, PhD Student
---------
Bases Mol?culaires et Structurales des Syst?mes infectieux-UMR5086
Institut de Biologie et Chimie des Prot?ines
7 passage du Vercors
<https://maps.google.com/?q=7+passage+du+Vercors&entry=gmail&source=g>
69 367 Lyon cedex 07
---------
Laboratoire de Biom?trie et Biologie Evolutive-UMR5558
UCBL Lyon 1 -B?t. Gr?gory Mendel
43 bd du 11 novembre 1918
<https://maps.google.com/?q=43+bd+du+11+novembre+1918&entry=gmail&source=g>
69622 VILLEURBANNE cedex

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171019/226596df/attachment-0001.html>

I think there was a bug in how you were capturing the clearing the children
of the top level frame. Tweaking it a bit I can reproduce the leaking, but
not on every cycle:

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.patches as patches
# from Tkinter import Tk, Canvas, Frame, Label, Button
from six.moves import tkinter as Tk
import gc
import resource
from matplotlib.figure import Figure
import sys

list_fig_g = []
list_wid_g = []

def launcher(list_wid, list_fig, frame):
    print('Memory usage: %s (kb)'
          % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss,)
    for f in list_fig:
        f.clf()
        f.clear()
        f._master = None
        del f
    list_fig.clear()

    for i in list_wid:
        print(i, sys.getrefcount(i))
        r = i.winfo_toplevel()
        i.grid_forget()
        i.destroy()
        for k in ('<MouseWheel>', '<Destroy>'):
            r.unbind(k)

        print(i, sys.getrefcount(i))
        del i
    list_wid.clear()

    fig1 = Figure(figsize=(1, 1))
    ax1 = fig1.add_subplot(111, aspect='equal')
    ax1.add_patch(
        patches.Arrow(
            0, # x
            -0, # y
            1, # dx
            0, # dy
            width=1,
        )
    )
    list_fig.append(fig1)
    # this seems to be the first line that leaks memory
    # but not _always_
    canvas = FigureCanvasTkAgg(fig1, master=None)

    t1, t2, w, h = fig1.bbox.bounds
    widget = canvas.get_tk_widget()

    # widget = Tk.Canvas(
    # master=frame, width=w, height=h, borderwidth=0,
    # highlightthickness=0)
    # w2 = Tk.PhotoImage(
    # master=widget, width=int(w), height=int(h))
    # widget.create_image(w//2, h//2, image=w2)
    widget.grid(row=0, column=1)
    widget.focus_set()
    list_wid.extend(frame.winfo_children())
    # print(w)
    # print('gc: ', gc.collect(2))
    gc.collect(2)
    # canvas.draw()
    print('Memory usage: %s (kb)'
          % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
    print()

def bulk(list_wid, list_fig, frame):
    for j in range(100):
        launcher(list_wid, list_fig, frame)

root = Tk.Tk()
Entete5 = Tk.Label(root, width=20, height=1).grid(row=0, column=1)
fond = Tk.Canvas(root, width=800, height=200)
fond.grid(row=1, column=1)
frame_g = Tk.Frame(fond, width=80, height=10)
frame_g.grid(row=0, column=1)
fond.create_window(0, 0, window=frame_g)
Load = Tk.Button(root, text="Load",
                 command=lambda: launcher(list_wid_g, list_fig_g, frame_g))
go = Tk.Button(root, text="bulk",
               command=lambda: bulk(list_wid_g, list_fig_g, frame_g))
Load.grid(row=7, column=4)
go.grid(row=6, column=4)
list_wid = frame_g.winfo_children()
root.mainloop()

(I also added a 'bulk' button to run 100 iterations). I tried just
creating a FigureCanvasAgg object (the super-class of FigureCanvasTkAgg)
and that seems not to leak. Doing most of the tk work
that FigureCanvasTkAgg does not seem to leak.

It looks like it is the callbacks that are registered to handle mouse and
key board events, deleteing them from the __init__ seems to prevent the
leak!

Not sure what the right way to clean those up is though, but at least this
is pointing the right direction!

Tom

···

On Thu, Oct 19, 2017 at 12:18 PM GARCIA PIERRE SIMON p0904379 < pierre.garcia at etu.univ-lyon1.fr> wrote:

Adding gc.collect() everywhere in the script doesn't change anything. Here
is a code that works and that is simpler:

#! /usr/bin/python2.7
#-*- coding: utf-8 -*-
import matplotlib
matplotlib.use('Tkagg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.patches as patches
from Tkinter import *
import gc
import resource
from matplotlib.figure import Figure

list_fig_g = []
list_wid_g = []

def Launcher(list_wid,list_fig,frame):
    print 'Memory usage: %s (kb)' %
resource.getrusage(resource.RUSAGE_SELF).ru_maxrss,
    for i in list_wid:
        i.grid_forget()
        i.destroy()
        del i
    try:
        list_fig[0].clf()# other round
        list_fig[0].clear()
        del list_fig[0]
    except:
        print "",# first round
    fig1 = Figure(figsize=(1,1))
    ax1 = fig1.add_subplot(111, aspect='equal')
    ax1.add_patch(
        patches.Arrow(
            0, # x
            -0, # y
            1, # dx
            0, # dy
            width=1,
        )
    )
    list_fig.append(fig1)
    canvas = FigureCanvasTkAgg(list_fig[0], master=frame)
    canvas.get_tk_widget().grid(row=0,column=1)
    list_wid = frame.winfo_children()
    print 'Memory usage: %s (kb)' %
resource.getrusage(resource.RUSAGE_SELF).ru_maxrss

root = Tk()
Entete5 = Label(root,width=20, height=1).grid(row=0,column=1)
fond = Canvas(root, width=800, height=200)
fond.grid(row=1, column=1)
frame_g = Frame(fond,width=80, height=10)
frame_g.grid(row=0,column=1)
fond.create_window(0, 0, window=frame_g)
Load = Button (root, text = "Load", command = lambda :
Launcher(list_wid_g,list_fig_g,frame_g))
Load.grid(row=7,column=4)
list_wid = frame_g.winfo_children()
root.mainloop()

and here is the output:

Memory usage: 49516 (kb) Memory usage: 50824 (kb)
Memory usage: 51880 (kb) Memory usage: 52672 (kb)
Memory usage: 52936 (kb) Memory usage: 53728 (kb)
Memory usage: 53992 (kb) Memory usage: 54256 (kb)
Memory usage: 54520 (kb) Memory usage: 54520 (kb)
Memory usage: 54520 (kb) Memory usage: 55048 (kb)
Memory usage: 55312 (kb) Memory usage: 55840 (kb)
Memory usage: 55840 (kb) Memory usage: 55840 (kb)
Memory usage: 56104 (kb) Memory usage: 56104 (kb)
Memory usage: 56104 (kb) Memory usage: 56104 (kb)
Memory usage: 56368 (kb) Memory usage: 56368 (kb)
Memory usage: 56368 (kb) Memory usage: 56632 (kb)
Memory usage: 56896 (kb) Memory usage: 57424 (kb)
Memory usage: 57688 (kb) Memory usage: 57688 (kb)
Memory usage: 57688 (kb) Memory usage: 57952 (kb)
Memory usage: 58216 (kb) Memory usage: 59008 (kb)
Memory usage: 59008 (kb) Memory usage: 59008 (kb)
Memory usage: 59008 (kb) Memory usage: 59272 (kb)
Memory usage: 59536 (kb) Memory usage: 60328 (kb)

Pierre
------------------------------
*De :* Thomas Caswell <tcaswell at gmail.com>
*Envoy? :* jeudi 19 octobre 2017 17:30
*? :* GARCIA PIERRE SIMON p0904379; Benjamin Root
*Cc :* matplotlib-users at python.org

*Objet :* Re: [Matplotlib-users] Problem of memory leak using
FigureCanvasTkAgg
Have you tried manually adding calls to `gc.collect(2)`? That may help to
clean up any circular reference cycles hanging around.

Can you replicate this with a simpler script? The code on SO is hard to
follow.

Tom

On Thu, Oct 19, 2017 at 10:56 AM GARCIA PIERRE SIMON p0904379 < > pierre.garcia at etu.univ-lyon1.fr> wrote:

Here is the diagnostic for the old version :

Memory usage: 39832 (kb) Memory usage: 45376 (kb)Memory usage: 46168 (kb) Memory usage: 46960 (kb)Memory usage: 47224 (kb) Memory usage: 47752 (kb)Memory usage: 47752 (kb) Memory usage: 48544 (kb)Memory usage: 48544 (kb) Memory usage: 48808 (kb)Memory usage: 48808 (kb) Memory usage: 49072 (kb)Memory usage: 49072 (kb) Memory usage: 49336 (kb)Memory usage: 49336 (kb) Memory usage: 49864 (kb)Memory usage: 49864 (kb) Memory usage: 50128 (kb)Memory usage: 50128 (kb) Memory usage: 50392 (kb)Memory usage: 50392 (kb) Memory usage: 50656 (kb)

and here is the diagnostic for 2.1.0:

Memory usage: 51808 (kb) Memory usage: 55504 (kb)
Memory usage: 57088 (kb) Memory usage: 57352 (kb)
Memory usage: 57880 (kb) Memory usage: 58144 (kb)
Memory usage: 58672 (kb) Memory usage: 58936 (kb)
Memory usage: 59464 (kb) Memory usage: 59464 (kb)
Memory usage: 59992 (kb) Memory usage: 60256 (kb)
Memory usage: 60520 (kb) Memory usage: 61048 (kb)
Memory usage: 61312 (kb) Memory usage: 61576 (kb)
Memory usage: 62104 (kb) Memory usage: 62368 (kb)
Memory usage: 62632 (kb) Memory usage: 63160 (kb)
Memory usage: 63424 (kb) Memory usage: 63688 (kb)
Memory usage: 64216 (kb) Memory usage: 64480 (kb)

It seems that the initial memory used is higher for 2.1.0.

For the delta against n and n+1, the value varies at the begin
and converge to 264 for 1.1.1 and 792 for 2.1.0.

So globally, the rate of leak increases in 2.1.0....

Pierre
------------------------------
*De :* Benjamin Root <ben.v.root at gmail.com>
*Envoy? :* jeudi 19 octobre 2017 16:32
*? :* GARCIA PIERRE SIMON p0904379
*Cc :* Thomas Caswell; matplotlib-users at python.org

*Objet :* Re: [Matplotlib-users] Problem of memory leak using
FigureCanvasTkAgg
Did the rate of memory leak change?

On Thu, Oct 19, 2017 at 10:26 AM, GARCIA PIERRE SIMON p0904379 < >> pierre.garcia at etu.univ-lyon1.fr> wrote:

Thank you for your answer but I updated MPL to 2.1.0 and the memory leak
is still there. Also, I skipped entirely pyplot and the result is strictly
the same.

Pierre
------------------------------
*De :* Benjamin Root <ben.v.root at gmail.com>
*Envoy? :* lundi 7 ao?t 2017 19:27
*? :* Thomas Caswell
*Cc :* GARCIA PIERRE SIMON p0904379; matplotlib-users at python.org
*Objet :* Re: [Matplotlib-users] Problem of memory leak using
FigureCanvasTkAgg

The stackoverflow posting notes that mpl v1.1.1 was used, which is 5
years old. I am pretty sure we have made a lot of memory leak fixes since
then. I noted as such on SO.

Ben Root

On Sat, Aug 5, 2017 at 7:48 PM, Thomas Caswell <tcaswell at gmail.com> >>> wrote:

It is likely there things are not being garbage collected due to either
a missed reference surviving or the circular references between the various
objects is delaying gc from collecting them (I do not recall the details
exactly off the top of my head, but running gc manually with more
generations may help).

However, if you are embedding in a GUI you are probably better off just
doing the embedding directly (and skipping `pyplot` entirely, see
https://matplotlib.org/examples/user_interfaces/embedding_in_tk.html ).
Re-using the Figures / Axes / Artists to update the data (rather than
starting from scratch every time) may also prevent the memory leaks _and_
give you a performance boost.

Please subscribe to the list so that you can post without moderation.

Tom

On Sat, Aug 5, 2017 at 12:36 PM GARCIA PIERRE SIMON p0904379 < >>>> pierre.garcia at etu.univ-lyon1.fr> wrote:

Hello,

I'm PhD student in Bioinformatic and I'm working on a project using
matplotlib and Tkinter but I've got a big problem of memory leak using
these modules. I'll be very grateful if you could help me to solve this
problem. Here is the link explaining what happends, with a reduced script:

http://stackoverflow.com/questions/43097378/matplotlib-vs-tkinter-memory-leak-using-figurecanvastkagg

Thank you in advance,

Sincerly,

Pierre Garcia, PhD Student
---------
Bases Mol?culaires et Structurales des Syst?mes infectieux-UMR5086
Institut de Biologie et Chimie des Prot?ines
7 passage du Vercors
<https://maps.google.com/?q=7+passage+du+Vercors&entry=gmail&source=g>
69 367 Lyon cedex 07
---------
Laboratoire de Biom?trie et Biologie Evolutive-UMR5558
UCBL Lyon 1 -B?t. Gr?gory Mendel
43 bd du 11 novembre 1918
<https://maps.google.com/?q=43+bd+du+11+novembre+1918&entry=gmail&source=g>
69622 VILLEURBANNE cedex

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171020/f3308701/attachment-0001.html>