Skip to content

Commit

Permalink
BUG : fixes FontProperties memory leak
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tacaswell authored and Joel B. Mohler committed Aug 14, 2014
1 parent 09d3d0d commit 4665ed6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/matplotlib/font_manager.py
Expand Up @@ -707,6 +707,12 @@ def __hash__(self):
self.get_file())
return hash(l)

def __eq__(self, other):
return hash(self) == hash(other)

def __ne__(self, other):
return hash(self) != hash(other)

def __str__(self):
return self.get_fontconfig_pattern()

Expand Down

0 comments on commit 4665ed6

Please sign in to comment.