Idomatic way to guarantee to run destructor?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon May 4 16:57:24 UTC 2020


On Mon, May 04, 2020 at 09:33:27AM -0700, Ali Çehreli via Digitalmars-d-learn wrote:
[...]
> Now it's news to me that 'new' does not allocate on the heap when
> 'scope' is used. I'm not sure I'm comfortable with it but that's true.
> Is this unique?  Otherwise, 'new' always allocates on the heap, no?

IIRC this is by design.  The idea is that if an object is 'scope', then
it will not escape the current scope and therefore it's safe to allocate
it on the stack instead of the heap.  IIRC historically this was a
semi-hack to allow people to specify that the object should be allocated
on the stack instead of the heap, back when the semantics of 'scope'
wasn't clearly defined yet.


T

-- 
Knowledge is that area of ignorance that we arrange and classify. -- Ambrose Bierce


More information about the Digitalmars-d-learn mailing list