How to use destroy and free.

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Apr 25 14:25:17 UTC 2022


On Mon, Apr 25, 2022 at 01:28:01PM +0000, Alain De Vos via Digitalmars-d-learn wrote:
> Could thc or hboehm provide solutions ?

In general, GC (of any kind) does not (and cannot) guarantee the order
objects will be collected in. So in the dtor, you cannot assume that any
objects you depend on still exist (they may have already been
collected).

There is also no guarantee that the object will *ever* get collected: in
theory, the GC may only collect just enough to make space for further
allocations, it's not obligated to collect *everything* that's
collectible. Or the collection might not take place before the end of
the program -- the GC may skip the final collection because it knows the
OS will reclaim everything automatically anyway.

Basically, deterministic destruction and GC are antithetical to each
other, and trying to have both is the road to trouble. If you wish to
have deterministic destruction, don't use the GC; use RAII or reference
counting instead.


T

-- 
What do you mean the Internet isn't filled with subliminal messages? What about all those buttons marked "submit"??


More information about the Digitalmars-d-learn mailing list