5852Re: "ocaml_beginners":: object finalization
- May 2, 2006On Tue, May 02, 2006 at 08:56:17AM +0200, Florent Monnier wrote:
> I would like that a method of an object to be called when this object isI think the answer is _no_, because calling the method of an object
> finalized. Is it possible ?
assumes that you have a pointer to the object around, and if you have
a pointer to the object around then the object can never become truly
unreachable, so it is never finalised :-(
Here is my test program. Note that the finaliser isn't called, and I
assume it's because self#finaliser contains a pointer (self) to the
let () =
let obj = object (self)
method hello = prerr_endline "hello"
method finaliser _ = prerr_endline "in finaliser"
prerr_endline "in initializer";
Gc.finalise self#finaliser self
(* cause the object to become unreachable *)
let obj = () in
(* call the garbage collector so the object should be finalised *)
prerr_endline "finished GC full major cycle"
It might be best to ask about this on caml-list ...
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com
- << Previous post in topic Next post in topic >>