Managing malloced memory

Imperatorn johan_forsberg_86 at
Mon Oct 11 12:09:07 UTC 2021

On Wednesday, 6 October 2021 at 18:06:38 UTC, anon wrote:
> I interface to a C library that gives me a malloced object. How 
> can I manage that pointer so that it gets freed automatically.
> What I've thought of so far:
> * scope(exit): not an option because I want to return that 
> memory
> * struct wrapper: Doesn't work because if I pass it to another 
> function, they also destroy it (sometimes). Also same problem 
> as with scope(exit)
> * struct wrapped in automem/ refcounted: The struct still 
> leaves original scope and calls the destructor

Explain again why scope exit isn't an option

More information about the Digitalmars-d-learn mailing list