Managing malloced memory

anon anon at
Wed Oct 6 19:22:51 UTC 2021

Sorry for messed up post, fixed it.

On Wednesday, 6 October 2021 at 18:29:34 UTC, Steven 
Schveighoffer wrote:
>You can return this thing and pass it around, and the GC will 
>keep it alive until it's not needed. Then on collection, the 
>value is freed.

Is the gc required to call ~this() on the struct? I remember it 
being implementation defined. Probably doesn't matter for my 
usecase, just curious.

>Why is it a problem that it calls the dtor? I thought the whole 
>point of refcounting is for the dtor to decrement the refcount, 
>and free the malloc'd object only when the refcount has actually 
>reached 0.

Yes I'm afraid of double freeing. How do I pass existing struct 
to refcounted without the already existing copy calling 
destructed on function exit.

More information about the Digitalmars-d-learn mailing list