strange work of GC

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 6 13:36:50 PST 2015


On Friday, 6 February 2015 at 20:38:07 UTC, Andrey Derzhavin 
wrote:
> As I think, the garbage collector should start destoying of the 
> C1 and C2 objects of arr array during the "while" cycle 
> prosess, but this does not
> happen. Dtors are not called.

The D GC only runs on demand - typically, when you allocate new 
memory is when the gc might run. This keeps totally hidden pauses 
from happening, so you at least can avoid a collection at a bad 
time for your program.

> If I use the GC.collect method after fn1, I get an error: 
> "core.exception.InvalidMemoryOperationError@(0)".
> Is this a bug of GC or I do something wrong?

You used GC memory from inside a destructor. That's an illegal 
operation; read the tip of the week from Sunday's newsletter to 
see a bit more:

http://arsdnet.net/this-week-in-d/feb-01.html


More information about the Digitalmars-d-learn mailing list