delete and references?

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri Aug 7 10:34:45 PDT 2009


On Fri, Aug 7, 2009 at 1:20 PM, Aaron Watters<arw1961 at yahoo.com> wrote:
> Hi guys.  D looks cool.  A couple of things confuse me.
> The first is: what happens if I do a
>
> delete cl;
>
> after storing a reference to cl somewhere?  Can I use the stored
> reference?  Is it invalid?  Please elucidate, thanks.

If you delete something and attempt to use another reference to the
deleted object, the behavior's undefined.  Basically the same thing as
accessing a dangling pointer in C or C++.  'delete' is really just
there for when you *know* that there are no other references and you
want to ensure that it gets cleaned up immediately.



More information about the Digitalmars-d mailing list