Skip to content

Commit

Permalink
destory() now cleanup SingleImages in the sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Oct 22, 2016
1 parent 29ce134 commit f97277b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/changes.rst
Expand Up @@ -15,6 +15,11 @@ To be released.
- Fixed :exc:`TypeError` during parsing version caused by format change of
ImageMagick version string (introduced by 6.9.6.2).
[:issue:`310`, `Debian bug report #841548`__]
- Properly fixed again memory-leak when accessing images constructed in
:class:`Image.sequence[] <wand.sequence.Sequence>`. It had still leaked
memory in the case an image is not closed using ``with`` but manual
:func:`wand.resource.Resource.destroy()`/:func:`wand.image.Image.close()`
method call. [:issue:`237`]

__ https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841548

Expand Down
11 changes: 6 additions & 5 deletions wand/image.py
Expand Up @@ -2757,15 +2757,16 @@ def __init__(self, image=None, blob=None, file=None, filename=None,
self.sequence = Sequence(self)
self.raise_exception()

def __exit__(self, type, value, traceback):
"""
Manually remove SingleImage's in the Sequence, allowing it to
be properly garbage collected after using a 'with Image()' context
def destroy(self):
"""Manually remove :class:`~.sequence.SingleImage`'s in
the :class:`~.sequence.Sequence`, allowing it to
be properly garbage collected after using a ``with Image()`` context
manager.
"""
for i in range(0, len(self.sequence)):
self.sequence.pop()
super(Image, self).__exit__(type, value, traceback)
super(Image, self).destroy()

def read(self, file=None, filename=None, blob=None, resolution=None):
"""Read new image into Image() object.
Expand Down

0 comments on commit f97277b

Please sign in to comment.