Skip to content

FIX: close mem leak for repeated draw #11972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ def __getstate__(self):
def __setstate__(self, data_dict):
self.__dict__ = data_dict
# turn the normal dictionary back into a dictionary with weak values
self._parents = {k: weakref.ref(v)
# The extra lambda is to provide a callback to remove dead
# weakrefs from the dictionary when garbage collection is done.
self._parents = {k: weakref.ref(v, lambda ref, sid=k,
target=self._parents:
target.pop(sid))
for k, v in self._parents.items() if v is not None}

def __copy__(self, *args):
Expand Down Expand Up @@ -169,7 +173,12 @@ def set_children(self, *children):
# parents are destroyed, references from the children won't
# keep them alive.
for child in children:
child._parents[id(self)] = weakref.ref(self)
# Use weak references so this dictionary won't keep obsolete nodes
# alive; the callback deletes the dictionary entry. This is a
# performance improvement over using WeakValueDictionary.
ref = weakref.ref(self, lambda ref, sid=id(self),
target=child._parents: target.pop(sid))
child._parents[id(self)] = ref

if DEBUG:
_set_children = set_children
Expand Down