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.


Reply via email to