When is a class's destructor called?
ponce
contact at gam3sfrommars.fr
Sun Dec 29 02:16:32 PST 2013
> Ok, I understand that, but since I don't have a garbage
> collector, what must I implement to call the destructor when it
> goes out of scope?
>
> Another way of asking the question is: How does the garbage
> collector know when something has gone out of scope and is
> therefore safe to collect? And where is that implemented in
> the runtime?
If you want deterministic destruction, you have plenty of choices:
- scoped!
- using structs instead
- scope(exit)
- RefCounted!
- Unique!
- ...
Yet using classes for ressources is not composable. It's either:
- using classes for the convenience and deal with resource
release manually
- using structs
It's an open quesiton for me which choice is best.
More information about the Digitalmars-d-learn
mailing list