class foo = object(dummy) initializer print_string "*** constructor\n"; Gc.finalise (fun _ -> print_string "*** destructor\n") dummy end;; new foo;; print_string "Foo was out-scoped.\n";; Gc.full_major ();; print_string "Gc was run.\n";; (* however, this can't really be used as a destructor since the closure *) (* given to Gc.finalise will retain a reference to the instance if *) (* anything in his environment reaches the object *) (* http://caml.inria.fr/pub/ml-archives/caml-list/2002/03/d61da155e0a36f4794e6ff02eed48ade.en.html *)