Garbage collector noob

torhu fake at address.dude
Tue Mar 6 21:15:16 PST 2007


I haven't dealt directly with the garbage collector much before, but 
just used delete and scope to deal with deallocation.  And left some of 
the minor allocations to be freed by the GC.

Now I want to work more closely with the GC.  Can anyone explain to me 
why fullCollect doesn't seem to do anything here?  This example just 
keeps allocating memory, until the GC seems to kick in to stop it from 
growing.  It stabilizes at 426MB.  The same example using Tango instead 
stops at 597MB.

---
import std.gc;

void main()
{
     int[] a;

     for (;;) {
         a = new int[1024 * 1024 * 10];
         a = null;
         assert(a.ptr is null);
         fullCollect();
     }
}
---

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?


More information about the Digitalmars-d-learn mailing list