[ocaml-ctypes] GC finalizer

Jeremy Yallop yallop at gmail.com
Fri Feb 6 11:21:03 GMT 2015


On 2 February 2015 at 20:16, Jacques-Pascal Deplaix
<jp.deplaix at gmail.com> wrote:
> I'm wondering how the values (pointers allocated on the heap) created by a C
> function, binded through ctypes should be freed. Is there a standard way to
> do that ?
>
> In my example, the memphis library allocate some memory in
> Memphis_renderer.create and should be freed via Memphis_renderer.destroy but
> is there a way to call memphis_renderer_destroy automatically using the
> OCaml GC ?

There are a few options.  The simplest thing may be to add a finaliser
(using Gc.finalise) to the pointer returned from
Memphpis_renderer.create that calls memphis_renderer_destroy.


More information about the Ctypes mailing list