Questions about initialization of array of objects

Andrey andr-sar at yandex.ru
Sat Jan 12 12:33:18 PST 2013


> If that array is allocated on the heap them mabye the GC will 
> ignore those class instances.

I think GC scans stack for pointers. At least, official manual 
says this:

The garbage collector looks for roots in:
1) the static data segment
2) the stacks and register contents of each thread
3) the TLS (thread-local storage) areas of each thread
4) any roots added by core.memory.GC.addRoot() or 
core.memory.GC.addRange()

If the only pointer to an object is held outside of these areas, 
then the collector will miss it and free the memory.


More information about the Digitalmars-d-learn mailing list