Destructing Member Objects
Simen Kjaeraas
simen.kjaras at gmail.com
Sat Apr 5 17:41:38 PDT 2008
On Sat, 05 Apr 2008 21:12:18 +0200, Brian White <bcwhite at pobox.com> wrote:
> I understand that you're not supposed to delete member within the
> destructor because, when called via the GC, it's possible that object
> has already been destructed.
>
> Is there a way for the object to determine if it's being destructed as
> part of a GC run or if it's being deleted explicitly?
>
> -- Brian
class foo
{
private ~this()
{
}
public kill()
{
// call any specific code you want here
delete this;
}
}
Then use foo.kill() instead of delete foo. Ugly, but works, I think.
More information about the Digitalmars-d-learn
mailing list