TDPL: Manual invocation of destructor
Lutger
lutger.blijdestijn at gmail.com
Tue Aug 10 10:20:47 PDT 2010
Max Samukha wrote:
...
> 2. Free the resource deterministically:
>
> auto owner = new ResourceOwner;
> owner.dispose();
>
> 3. RAII:
>
> using (auto owner = new ResourceOwner)
> {
> ...
> }
>
> The resource will be freed at the end of the "using" block.
>
> Is it possible to realize 2-3 in D using clear()/scoped()?
I don't think it is possible, because owner.resource could be garbage collected
before owner itself is. That would conflict with the first case. If you can
forgot about that case it is easy to do with scope(exit) and leaving the
destructor out, if you rewrite it as a struct even better.
More information about the Digitalmars-d
mailing list