Revision: 5747
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5747&view=rev
Author: mdboom
Date: 2008-07-11 11:21:53 -0700 (Fri, 11 Jul 2008)
Log Message:
-----------
Fix memory leak when using shared axes.
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/cbook.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2008-07-11 16:30:07 UTC (rev 5746)
+++ trunk/matplotlib/CHANGELOG 2008-07-11 18:21:53 UTC (rev 5747)
@@ -1,3 +1,6 @@
+2008-07-11 Fix memory leak related to shared axes. Grouper should
+ store weak references. - MGD
+
2008-07-10 Bugfix: crash displaying fontconfig pattern - MGD
2008-07-10 Bugfix: [ 2013963 ] update_datalim_bounds in Axes not works - MGD
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-11 16:30:07 UTC (rev
5746)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-11 18:21:53 UTC (rev
5747)
@@ -904,6 +904,8 @@
self.xaxis.set_clip_path(self.patch)
self.yaxis.set_clip_path(self.patch)
+ self._shared_x_axes.clear()
+ self._shared_y_axes.clear()
def clear(self):
'clear the axes'
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-11 16:30:07 UTC (rev
5746)
+++ trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-11 18:21:53 UTC (rev
5747)
@@ -6,6 +6,7 @@
import re, os, errno, sys, StringIO, traceback, locale, threading
import time, datetime
import numpy as np
+from weakref import ref
major, minor1, minor2, s, tmp = sys.version_info
@@ -1042,24 +1043,34 @@
def __init__(self, init=[]):
mapping = self._mapping = {}
for x in init:
- mapping[x] = [x]
+ mapping[ref(x)] = [ref(x)]
def __contains__(self, item):
- return item in self._mapping
+ return ref(item) in self._mapping
+ def clean(self):
+ """
+ Clean dead weak references from the dictionary
+ """
+ mapping = self._mapping
+ for key, val in mapping.items():
+ if key() is None:
+ del mapping[key]
+ val.remove(key)
+
def join(self, a, *args):
"""
Join given arguments into the same set. Accepts one or more
arguments.
"""
mapping = self._mapping
- set_a = mapping.setdefault(a, [a])
+ set_a = mapping.setdefault(ref(a), [ref(a)])
for arg in args:
- set_b = mapping.get(arg)
+ set_b = mapping.get(ref(arg))
if set_b is None:
- set_a.append(arg)
- mapping[arg] = set_a
+ set_a.append(ref(arg))
+ mapping[ref(arg)] = set_a
elif set_b is not set_a:
if len(set_b) > len(set_a):
set_a, set_b = set_b, set_a
@@ -1067,13 +1078,17 @@
for elem in set_b:
mapping[elem] = set_a
+ self.clean()
+
def joined(self, a, b):
"""
Returns True if *a* and *b* are members of the same set.
"""
+ self.clean()
+
mapping = self._mapping
try:
- return mapping[a] is mapping[b]
+ return mapping[ref(a)] is mapping[ref(b)]
except KeyError:
return False
@@ -1083,6 +1098,8 @@
The iterator is invalid if interleaved with calls to join().
"""
+ self.clean()
+
class Token: pass
token = Token()
@@ -1090,7 +1107,7 @@
# and don't yield it twice
for group in self._mapping.itervalues():
if not group[-1] is token:
- yield group
+ yield [x() for x in group]
group.append(token)
# Cleanup the tokens
@@ -1102,9 +1119,12 @@
"""
Returns all of the items joined with *a*, including itself.
"""
- return self._mapping.get(a, [a])
+ self.clean()
+ siblings = self._mapping.get(ref(a), [ref(a)])
+ return [x() for x in siblings]
+
def simple_linear_interpolation(a, steps):
steps = np.floor(steps)
new_length = ((len(a) - 1) * steps) + 1
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins