When I should to call destroy?
Cauterite via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 29 06:31:59 PDT 2016
On Friday, 29 July 2016 at 13:18:00 UTC, Suliman wrote:
> 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?
`destroy` is mainly about running destructors deterministically.
From the source comments:
> "It's used to destroy an object so that any cleanup which its
> destructor or finalizer does is done and so that it no longer
> references any other objects."
For example, your object might allocate a large amount of
manually-managed memory, and you don't want that allocation
laying around until the next GC cycle, so you can use `destroy`
to finalise your object as early as possible to release that
manually-managed allocation.
If you really want to deallocate the object's own memory, you can
check out core.memory.GC.query() / core.memory.GC.free().
More information about the Digitalmars-d-learn
mailing list