Garbage collector noob

torhu fake at address.dude
Wed Mar 7 00:15:12 PST 2007

Sean Kelly wrote:
> When I run the test on Tango, memory juse jumps to 467k and stays steady 
> there.  Doing some quick math with a calculator shows an array 1024^2*10 
> integers should occupy ~409k of memory, so the rest is just program 
> overhead.  For what it's worth, running this app on Tango without the 
> call to gc.collect() brings memory use up to 594k.  I'd have to debug 
> the GC to figure out why.

Uh... but 1024^2*10 ints is 40 MB exactly.  Are you talking about a 
different test program?

>> Removing the call to fullCollect() doesn't change the behavior.  I 
>> expected fullCollect to collect as much memory as it can, and then reuse 
>> it for the next allocation.  Am I on the wrong track here?
> Nope.  That's what it should do.  But be aware that the current GC 
> allocates memory in pages and those pages are devoted to a specific size 
> of data.  And once so assigned, I don't think the GC ever attempts to 
> reclaim empty pages if another size allocation is required.  It doesn't 
> matter in this case because anything over a page (4k) is the same "size" 
> as far as the GC is concerned, but it may matter in an app that 
> allocates a ton of small objects and discards them, then allocates a ton 
> of larger objects and discards them, etc.

Are you on Windows or Linux?  I'm on windows, and I'm not seeing the 
behavior you describe.  The test I posted allocates the same amount of 
memory over and over again.  But the GC doesn't seem to start reusing it 
until somewhere around the eleventh time through the loop.  Until then 
it just grows.

Just for the record, the number I'm looking at is 'private bytes' in 
process explorer, which is the same as 'VM size' in task manager.  Which 
shows allocated heap memory, and probably some other stuff.  And I use 
dmd 1.007.

More information about the Digitalmars-d-learn mailing list