8000 FIX: squash memory leak for redraws · matplotlib/matplotlib@2f0a96c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f0a96c

Browse files
committed
FIX: squash memory leak for redraws
1 parent 9f74ea7 commit 2f0a96c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/matplotlib/transforms.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ def set_children(self, *children):
169169
# parents are destroyed, references from the children won't
170170
# keep them alive.
171171
for child in children:
172-
child._parents[id(self)] = weakref.ref(self)
172+
# pass a weak reference. The second arg is a callback for
173+
# when the weak ref is garbage collected to also
174+
# remove the dictionary element, otherwise child._parents
175+
# keeps growing for multiple draws.
176+
ref = weakref.ref(self, lambda ref, sid=id(self),
177+
target=child._parents: target.pop(sid))
178+
child._parents[id(self)] = ref
173179

174180
if DEBUG:
175181
_set_children = set_children

0 commit comments

Comments
 (0)
0