Don't expect class destructors to be called at all by the GC
user1234
user1234 at 12.fr
Thu Dec 21 04:10:56 UTC 2017
On Thursday, 21 December 2017 at 02:57:00 UTC, Mike Franklin
wrote:
> "Don't expect class destructors to be called at all by the GC"
>
> I was a bit shocked to read that here:
> https://p0nce.github.io/d-idioms/#The-trouble-with-class-destructors
>
> The document tries to clarify with:
> "The garbage collector is not guaranteed to run the destructors
> for all unreferenced objects."
>
> Unfortunately, that doesn't really shed much light on this
> oddity. So, specifically, under what circumstances are
> destructors not called?
>
> Thanks,
> Mike
When the GC is unaware of a class instance (an "unreferenced
object") it won't call its destructor. This happens when you use
alternative memory management strategy, for example using
Mallocator and make you get an unreferenced object that you have
to manage yourself.
More information about the Digitalmars-d-learn
mailing list