Skip to content

Commit

Permalink
Fix memory leak in MinHash.intersection. (#687)
Browse files Browse the repository at this point in the history
The intersection function uses the `new` operator to construct
a `KmerMinHash` or `KmerMinAbundance`. Although this is Cython,
`new` still heap-allocates the object, and it is *not* marked
for garbage collection, because it isn't a PyObject. This commit
calls delete (`del`) on the allocated object to prevent it from
being leaked.
  • Loading branch information
camillescott authored and luizirber committed Jun 6, 2019
1 parent ab0279a commit 6bd362f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sourmash/_minhash.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ cdef class MinHash(object):
common.intersection_update(other.get_mins())
common.intersection_update(combined_mh.mins)

return common, max(combined_mh.size(), 1)
size = max(combined_mh.size(), 1)
del combined_mh

return common, size

def compare(self, MinHash other):
common, size = self.intersection(other)
Expand Down

0 comments on commit 6bd362f

Please sign in to comment.