[plt-scheme] memory leak (program attached)

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Nov 15 11:50:34 EST 2008

At Sat, 15 Nov 2008 16:32:22 +0000, Vladimir Konrad wrote:
> > I am trying to trace memory leak in program, which loads images and
> > samples the pixels (the file attached works but leaks memory).
> > Is there a better way to do this?
> Seems that a simpler approach (without going through bitmap-dc) using
> bitmap object directly (to get the pixels) works without memory leak...

I think you're seeing a bad interaction between generational collection
and finalization of graphics objects.

If I remove the `list' call from the inner loop in your code, then
memory use seems to be bounded better. I think it's because the `list'
calls trigger GCs that make the bitmap and its DC survive into the
older generation. Then, due to the link from the DC to the bitmap and
the ordering of finalizations, it takes two major collections to purge
the bitmap.

If that's correct, you'd also get better results by adding `(send
bitmap-dc set-bitmap #f)' after the bitmap is used.

There's a check in the system that triggers extra major collections
when the number of bitmaps grows (because bitmaps and finalization
interact badly in many ways). So, the system will eventually reach a
steady state for your program --- but at much higher memory use than if
the link is broken explicitly.


Posted on the users mailing list.