On Friday, 14 April 2023 at 04:43:39 UTC, Paul Backus wrote:

If you want the GC to clean up your memory, use `new` to allocate it instead of `malloc`. Like this:

```d
mystruct* getmystruct()
{
    return new mystruct;
}
```

That won't work because the C++ programm calling the D dynlib will not have its stack scanned, leading to that object being reclaimed early.

OP could add another extern(C) D function to free the allocated object.
Or another extern(C) D function to call GC.addRoot

Reply via email to