Garbage collector noob

Sean Kelly sean at f4.ca
Wed Mar 7 07:49:15 PST 2007


torhu wrote:
> 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?

No, you're right.  I misread the output to contain one more zero than it 
does.

>>> 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.

Windows.  The app jumps to 467k almost immediately and stays there.  I 
haven't tried stepping through the loop, so it may just be happening too 
fast for me to see.

> 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.

Thanks, I'll check that number to be sure.


Sean


More information about the Digitalmars-d-learn mailing list