Why not memory specific destructors?
via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 6 04:00:29 PDT 2014
On Monday, 5 May 2014 at 18:08:22 UTC, Frustrated wrote:
> So, instead of removing destructors why not have multiple
> types? If the object is manually allocated then we can
> guarantee the destructor will be called when the object is
> free'ed.
>
> But basically, since they would be different types of
> destructors there would be no confusion about when they would
> or wouldn't be called.
>
> 1. GC destructors - Never called when the object is managed by
> the GC. (or maybe one can flag certain ones to always be called
> and the GC will respect that)
>
> 2. Manual memory management destructors - Always called when
> the object is allocated by manually.
>
> 3. Others(ARC, etc) - Same principle.
I don't see a need to distinguish between all possible ways of
memory management. The key distinction is whether it's reliable
or not. RAII/scope and manual management are deterministic and
reliable, tracing GC is not, and ARC only if cycles are
disallowed.
Destructors of the first kind are usually called just destructors
and are used for resource management, and the second kind are
called finalizers. These are useful for implementing weak
references, caching, and various other things where you don't
require objects to be destroyed at a certain point in time, but
still want to get notified when they are.
More information about the Digitalmars-d
mailing list