From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA27497 for caml-redistribution; Mon, 13 Dec 1999 17:26:00 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA25246 for ; Mon, 13 Dec 1999 13:50:51 +0100 (MET) Received: from tobago.inria.fr (tobago.inria.fr [128.93.8.21]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id NAA06404 for ; Mon, 13 Dec 1999 13:50:50 +0100 (MET) Received: (from doligez@localhost) by tobago.inria.fr (8.6.10/8.6.6) id NAA14523 for caml-list@inria.fr; Mon, 13 Dec 1999 13:50:48 +0100 Date: Mon, 13 Dec 1999 13:50:48 +0100 From: Damien Doligez Message-Id: <199912131250.NAA14523@tobago.inria.fr> To: caml-list@inria.fr Subject: Re: Finalisation in 2.02 Sender: weis >From: skaller >I'm still using ocaml 2.02, and have encountered what looks like a bug, >although perhaps it is my understanding, and perhaps it is fixed >in 2.04, or will be in 3. IIRC, nothing was changed in that part of the system between 2.02 and 2.04. >The problem is that when I create an object with alloc_final(_,_,0,1), >the finaliser is not called on termination. Using 1,1 seems to cause >it to be called almost immediately. (0,1) means "don't change the current GC schedule". It is appropriate when the resources used by the block (besides heap memory) are negligible. (1,1) means "do a major collection right now". >I'm modifying mlgtk by boxing GtkObjects, this seems necessary >to allow the collector to call the finaliser which decrements >the reference count -- however, at least the memory of the object >doesn't seem to be released when caml terminates. That's right. You could say that "exit" deallocates everything, but the finalisers are not called for that kind of deallocation, only for normal deallocation during the program's execution. >Perhaps I should force a full GC collection, just before >termination? That would be a workable solution. But blocks reachable from global variables still won't be finalised. > [I seem to also get this >behaviour with output to stdout -- I have to flush the file >after every write, in case an exception terminates the program, >and these debugging writes are there precisely to track this] You should have a look at the Printexc module. A side effect of using Printexc.catch is that I/O buffers will be flushed before the program terminates. -- Damien