[ocaml-ctypes] GC finalizer

Jacques-Pascal Deplaix jp.deplaix at gmail.com
Fri Feb 6 17:55:15 GMT 2015


Thanks a lot !

On 02/06/2015 11:21 AM, Jeremy Yallop wrote:
> 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