Destructor order
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 22 11:14:44 PDT 2014
On Wed, 22 Oct 2014 18:03:44 +0000
anonymous via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> On Wednesday, 22 October 2014 at 15:45:02 UTC, eles wrote:
> > D version:
> >
> > { //displays ~A~B~C
> > A foo = scoped!(A)();
> > B bar = scoped!(B)();
> > C caz = new C();
> > destroy(caz);
> > }
> >
> > Why the objects are not destroyed in the inverse order of their
> > creation? Case in point, destroying foo releases a lock for bar
> > and caz.
>
> `foo` should be a `Scoped!A`. When it's typed as `A`, the
> `Scoped!A` that is returned by `scoped`, is destructed
> immediately (and the reference leaks, I guess).
yes, this is the case. i believe that this should be explicitly
documented in `scoped` ddocs. documentation examples using 'auto', but
there is no mention that this is what *must* be used.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141022/854b9f3b/attachment.sig>
More information about the Digitalmars-d-learn
mailing list