Can't I allocate at descontructor?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Mar 5 20:13:45 UTC 2021


On Fri, Mar 05, 2021 at 08:03:58PM +0000, Jack via Digitalmars-d-learn wrote:
> On Friday, 5 March 2021 at 09:23:29 UTC, Mike Parker wrote:
> > On Friday, 5 March 2021 at 05:31:38 UTC, Jack wrote:
> > > The following code returns a memory error. I did notice it did
> > > happens whenever I did a memory allocation. Is this not possible
> > > in the descontrutor? if so, why?
> > 
> > https://dlang.org/blog/2021/03/04/symphony-of-destruction-structs-classes-and-the-gc-part-one/
> 
> thanks for such good article. So if the object was allocated on heap,
> there's no guarantee that the object's destrutor will be called at all?

Yes.

And also if it does get called, there's no guarantee what order it will
be called in w.r.t. other dtors. And you cannot perform any GC
operations in it.


> do destrutor allocate at stack are guarantee to be run?

Yes.


T

-- 
If it tastes good, it's probably bad for you.


More information about the Digitalmars-d-learn mailing list