Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3b18a2

Browse files
committed
BUG : fixes FontProperties memory leak
According to the data model (https://docs.python.org/2/reference/datamodel.html#object.__hash__) objects that define __hash__ need to define __eq__ or __cmp__. By default, all user defined classes have a __cmp__ which evaluates to False for all other objects. Previously we do not define either __cmp__ or __eq__ on FontProperties, This results in never finding the property cached in the dict, hence the growth in the number of FontProperties (and I assume the stuff in them). By adding __eq__ and __ne__ we complete the data model and adding FontProperties to dictionaries should work as expected. This was not a problem before, but in matplotlib#3077 the caching key was changed from hash(prop) -> prop. Closes matplotlib#3264
1 parent 71dc35a commit a3b18a2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/matplotlib/font_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ def __hash__(self):
707707
self.get_file())
708708
return hash(l)
709709

710+
def __eq__(self, other):
711+
return hash(self) == hash(other)
712+
713+
def __ne__(self, other):
714+
return hash(self) != hash(other)
715+
710716
def __str__(self):
711717
return self.get_fontconfig_pattern()
712718

0 commit comments

Comments
 (0)