Should destructors be able to tell who called them?

Sean Kelly sean at invisibleduck.org
Tue Aug 10 13:03:58 PDT 2010


That hook was really added for other purposes anyway.  I mostly wanted to note that it's possible to try this out now without any language changes.

Yao G. Wrote:

> Thanks for this Sean. Although I concur with Steve that it looks weird, at  
> least is usable.
> 
> Yao G.
> 
> 
> On Tue, 10 Aug 2010 13:51:56 -0500, Sean Kelly <sean at invisibleduck.org>  
> wrote:
> 
> > Steven Schveighoffer Wrote:
> >
> >> One of the common problems of destructors is that they cannot assume any
> >> of their GC-allocated resources are valid when inside the destrutor.
> >
> > Just a note.  It's already possible to do this in D2 using an  
> > interface.  Here's a thread about it:
> >
> > http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=89443&header
> >
> > And some sample code:
> >
> > import core.runtime;
> >
> > interface Disposable
> > {
> >     void dispose();
> > }
> >
> > bool handler( Object o )
> > {
> >     auto d = cast(Disposable) o;
> >
> >     if( d !is null )
> >     {
> >         d.dispose();
> >         return false;
> >     }
> >     return true;
> > }
> >
> > static this()
> > {
> >     Runtime.collectHandler = &handler;
> > }
> 
> 
> -- 
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list