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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to