When I should to call destroy?

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 29 06:18:00 PDT 2016


Use the `destroy` function to finalize an object by calling its 
destructor. The memory of the object is not immediately 
deallocated, instead the GC will collect the memory of the object 
at an undetermined point after finalization:

class Foo { int x; this() { x = 1; } }
Foo foo = new Foo;
destroy(foo);
assert(foo.x == int.init);  // object is still accessible


But I can't understand if D have GC it should remove objects when 
their life is finished. When I should to call `destroy`? What 
would be if I will not call it?


More information about the Digitalmars-d-learn mailing list