What should happen here?

Steven Schveighoffer schveiguy at gmail.com
Wed Sep 22 12:31:48 UTC 2021


On 9/22/21 8:12 AM, Kagamin wrote:
> On Monday, 20 September 2021 at 18:49:12 UTC, Steven Schveighoffer wrote:
>> This to me seems like "leaving a pointer to it on the stack". I'm not 
>> sure how else I would do that specifically? Plus, this option is the 
>> only "free" one -- the others all require much more complication. 
>> Adding a pointer to the stack is free. It's just, I don't know how to 
>> tell the compiler to do that besides declaring it.
> 
> If you use the pointer after the call, that's an easy way to ensure that 
> the pointer is kept around long enough.

And by the way I tried naive usage, and the compiler saw right through that:

```d
auto c = new C;
scope(exit) auto fake = c; // still collected early
```

-Steve


More information about the Digitalmars-d mailing list