[racket] bitmap% size in memory

From: Bert De Ketelaere (bedeke at hotmail.com)
Date: Wed Dec 19 10:26:53 EST 2012

Thank you for the answer,

That explains why loading a bitmap (without the shadow byte-string)
didn't raise the the value reported by current-memory-use.

I'm wondering now in what way this helps the GC and the memory-limit checks?
The reason I started looking into this was that DrRacket kept running out of memory
and closing down without a warning (even with a memory limit set to 512 MB).
So to me it seems that for current-memory-use and DrRacket's memory limit check
this trick doesn't really work.  But maybe this is not the intended purpose of the
shadow byte-string.

Bert


> From: mflatt at cs.utah.edu
> To: bedeke at hotmail.com
> CC: users at racket-lang.org
> Subject: Re: [racket] bitmap% size in memory
> Date: Wed, 19 Dec 2012 07:11:24 -0700
> 
> 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
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121219/ba3871e7/attachment-0001.html>

Posted on the users mailing list.