Cleanup class after method?

Mr.Bingo Bingo at Namo.com
Wed Jul 4 15:55:51 UTC 2018


On Wednesday, 4 July 2018 at 15:47:25 UTC, JN wrote:
> Imagine I have a very short-lived class:
>
> void print(File f)
> {
>     PrinterManager pm = new PrinterManager();
>     pm.print(f);
> }
>
> My understanding is that PrinterManager will be GC allocated, 
> and when it goes out of scope, the GC will possibly clean it up 
> at some point in the future. But I know that this class won't 
> be used anywhere, I want to clean it up right now so that GC 
> doesn't waste time later. In C++ it'd be handled by RAII, pm 
> would be a unique_ptr<PrinterManager>. How to do it in D?

https://dlang.org/phobos/std_typecons.html#scoped


More information about the Digitalmars-d-learn mailing list