`free` for struct with C bindings.

ag0aep6g anonymous at example.com
Mon May 14 22:12:41 UTC 2018

On 05/15/2018 12:03 AM, Jonathan wrote:
> ```
> xcb_generic_event_t*    event;
> event = xcb_wait_for_event (connection);
> free (event);
> ```
> The problem is the `free` function.  It is not provided by the library 
> but is part of the C standard library (in stdlib.h).

D has the C functions in core.stdc. So:

     import core.stdc.stdlib: free;

> I tried using the 
> `core.memory.GC.free` function from the D standard library and it 
> compiled and ran but that does not necessarily mean there are not memory 
> leaks (it also ran with the line entirely removed).

core.memory.GC.free is a different function. It works on GC-managed 
pointers. Don't call it on pointers that come from C libraries.

More information about the Digitalmars-d-learn mailing list