[Image-SIG] memory flush?

Mark Wendell mark.wendell at gmail.com
Thu Jun 14 05:36:42 CEST 2007

I'm working on some code that computes weighted averages of a series
of images. I do this by loading a subset of the large image list
(maybe a dozen images at a time), computing their average, and then
saving the result image to disk. Once I'm done with that subset, I
load a new batch and repeat.

The problem is that over time, I start swapping and eventually get
memory-related overflow problems.

Here's the output of a typical memory crash:

Error in sys.excepthook:
Traceback (most recent call last):
  File "/var/lib/python-support/python2.5/apport_python_hook.py", line
30, in apport_excepthook
    import apport.report, apport.fileutils
  File "/var/lib/python-support/python2.5/apport/__init__.py", line 1,
in <module>
    from apport.report import Report
  File "/var/lib/python-support/python2.5/apport/report.py", line 20,
in <module>
    from problem_report import ProblemReport
  File "/var/lib/python-support/python2.5/problem_report.py", line 17,
in <module>
    from email.MIMEMultipart import MIMEMultipart
  File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 79, in

  File "email/mime/multipart.py", line 9, in <module>
  File "email/mime/base.py", line 9, in <module>
ValueError: bad marshal data

Original exception was:
Traceback (most recent call last):
  File "/home/mark/sandbox/im_retimer/retimer_tester.py", line 24, in <module>
  File "/home/mark/sandbox/im_retimer/im_retimer.py", line 80, in
    self.tmpImg = Image.blend(self.blackImg, self.imObjStack[i],
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1944, in blend
    return im1._new(core.blend(im1.im, im2.im, alpha))

The thing is that I have plenty of memory for any given batch. The
problem seems to be that PIL or python is not doing a good job of
automatically flushing memory of image objects that I don't use

So my question is: is there a way to force the flushing from memory of
image objects I no longer need? Any other ideas for managing this kind
of overflow? Over time, my program may try to load hundreds of images,
but I only need to run computations on a few at a time.


Mark Wendell

More information about the Image-SIG mailing list