I think I'm on to something -- it seems that text layout information has a cyclical reference that prevents the Text object from being freed.

Can you apply the attached patch and let me know if it solves your issue?

Mike

On 12/10/2010 02:19 PM, Russell E. Owen wrote:
You may have already seen this in the general mailing list, but I've
found what I think is a serious memory leak in matplotlib 1.0.0: it
leaks memory every time canvas.draw() is called, at least when using
TkAgg on unix and Mac.

Admittedly many graphs do not need canvas.draw() to be called repeatedly
(which I suspect is how it has survived this long). This came up in the
context of a strip chart widget, where I am changing the x/time axis
limits regularly and calling canvas.draw() so that the change is visible.

I submitted ticket 3124990 with a very simple demo script:
<https://sourceforge.net/tracker/?func=detail&atid=560720&aid=3124990&gro
up_id=80706>
(you can disable the setting the x limits if you want to see the leak in
its purest form, but then nothing changes visually on the graph).

I just wanted to be sure folks know about it in hopes somebody might
have an idea how to fix it. I have not tried any other back ends.

-- Russell


------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages,
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

Index: lib/matplotlib/cbook.py
===================================================================
--- lib/matplotlib/cbook.py	(revision 8819)
+++ lib/matplotlib/cbook.py	(working copy)
@@ -1109,9 +1109,10 @@
         dict.__init__(self)
         self.maxsize = maxsize
         self._killkeys = []
+
     def __setitem__(self, k, v):
         if k not in self:
-            if len(self)>=self.maxsize:
+            if len(self) >= self.maxsize:
                 del self[self._killkeys[0]]
                 del self._killkeys[0]
             self._killkeys.append(k)
Index: lib/matplotlib/text.py
===================================================================
--- lib/matplotlib/text.py	(revision 8819)
+++ lib/matplotlib/text.py	(working copy)
@@ -143,6 +143,9 @@
     Handle storing and drawing of text in window or data coordinates.
     """
     zorder = 3
+
+    cached = maxdict(50)
+
     def __str__(self):
         return "Text(%g,%g,%s)"%(self._y,self._y,repr(self._text))
 
@@ -168,7 +171,6 @@
         """
 
         Artist.__init__(self)
-        self.cached = maxdict(5)
         self._x, self._y = x, y
 
         if color is None: color = rcParams['text.color']
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to