[Mono-devel-list] GC with Pixbufs
Miguel de Icaza
miguel at ximian.com
Mon Mar 15 15:13:43 EST 2004
Hello,
> I have a program that generates thumbnails of images for web pages.
> Creating a thumbnail simply involves reading the file into a Pixbuf
> image, scaling it into a new Pixbuf and saving it.
>
> Mono doesn't seem to ever GC these Pixbufs. They are only referenced
> from local variables in functions when the thumbnail is being created so
> I'm sure they're elligible for deallocation.
The problem is that the memory consumption happens in unmanaged world,
so the GC has no way of knowing that your very few allocations that you
have performed each one has a big impact.
For example, say that the Pixbuf takes 32 bytes of RAM, but the actual
data pointed to takes 6 megabytes. If you allocate 256 of these
objects, as far as the GC is concerned, you have barely allocated 8k of
GC memory, so it is not worth doing a collection for that little memory.
You should use the explicit Dispose method of Pixbuf in these cases
(since you are using an unmanaged resource that the managed world has no
idea what it is).
Miguel
More information about the Mono-devel-list
mailing list