Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3325bde

Browse files
committed
FIX: squash memory leak for redraws
1 parent9f74ea7 commit3325bde

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

‎lib/matplotlib/transforms.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ def __getstate__(self):
111111
def__setstate__(self,data_dict):
112112
self.__dict__=data_dict
113113
# turn the normal dictionary back into a dictionary with weak values
114-
self._parents= {k:weakref.ref(v)
114+
# The extra lambda is to provide a callback to remove dead
115+
# weakrefs from the dictionary when garbage collection is done.
116+
self._parents= {k:weakref.ref(v,lambdaref,sid=k,
117+
target=self._parents:
118+
target.pop(sid))
115119
fork,vinself._parents.items()ifvisnotNone}
116120

117121
def__copy__(self,*args):
@@ -169,7 +173,12 @@ def set_children(self, *children):
169173
# parents are destroyed, references from the children won't
170174
# keep them alive.
171175
forchildinchildren:
172-
child._parents[id(self)]=weakref.ref(self)
176+
# Use weak references so this dictionary won't keep obsolete nodes
177+
# alive; the callback deletes the dictionary entry. This is a
178+
# performance improvement over using WeakValueDictionary.
179+
ref=weakref.ref(self,lambdaref,sid=id(self),
180+
target=child._parents:target.pop(sid))
181+
child._parents[id(self)]=ref
173182

174183
ifDEBUG:
175184
_set_children=set_children

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp