Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
wrapping external classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] wrapping external classes
Mauricio Fernandez wrote:
> class foo s n =
> object(self)
>   val handle = create s n
>   method compute = compute handle
>   initializer
>     (* use a destroy method explicitly if you need to make sure the destructor
>      * is called --- Gc.finalise doesn't guarantee this (e.g. the program might
>      * terminate before the finalisation function is executed) *)
>     Gc.finalise destroy handle
> end

If the handle is really an OCaml integer, it is not possible to attach a 
finalizer to it. The finalizer could be attached to the object that 
wraps the handle; but the best solution is to use custom blocks and C 
finalizers in the C binding.

-- Alain