[racket] bitmap% size in memory

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Dec 19 09:11:24 EST 2012

The "shadow" byte string is indeed unused. It's there only as an
accounting trick for Racket's garbage collector.

The memory used for the actual bitmap is not visible to the garbage
collector, so it doesn't directly count towards a program's (or
custodian's) memory use. The shadow byte string is allocated and kept
alive during the same time as an actual bitmap to create GC-visible
memory use. That is, the shadow byte string triggers full garbage
collections and memory-limit checks as needed to keep the system as a
whole working right.

This trick does use about twice the memory that a bitmap would
otherwise use, but it makes the garbage collector and bitmaps play
nicely without complex changes to the garbage collector.

At Wed, 19 Dec 2012 08:10:37 +0100, Bert De Ketelaere wrote:
> 
> Hello all,
> 
> When loading large pictures (± 4300x2600 pixels) I would expect that they takes 
> up around 45Mb of memory.
> But when I monitored my program in windows task-manager I noticed it was more 
> in the neighborhood of 100Mb (after garbage collection, the in-between values 
> goes over 200Mb)
> Hoping to find a reason for this I went looking into racket/draw/bitmap and 
> noticed that there is a variable "shadow" that is set to a zeroed out 
> byte-string, the size of the picture.  But the only thing happening with this 
> "shadow" is it's definition and a set!.  It is never read.
> I tried removing the two references to "shadow", and in my programs everythings 
> seems to keep working, with the added bonus that the picture now indeed takes 
> only around 45Mb instead of 100Mb.
> 
> two questions:
> As far as I understand classes, since shadow is locally defined, no parent or 
> child can access shadow, so removing it should be ok.  Is this right?
> Is there a way to see how much memory an object occupies?
> 
> Bert
> 
>  		 	   		  ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.