From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA30972; Mon, 19 Mar 2001 11:49:43 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 LAA22282 for ; Mon, 19 Mar 2001 11:49:41 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f2JAnd909394; Mon, 19 Mar 2001 11:49:39 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA30751; Mon, 19 Mar 2001 11:49:38 +0100 (MET) Date: Mon, 19 Mar 2001 11:49:38 +0100 From: Xavier Leroy To: Chris Hecker Cc: caml-list@inria.fr Subject: Re: [Caml-list] faq? gc'd channels & finalize? Message-ID: <20010319114938.B30440@pauillac.inria.fr> References: <4.3.2.7.2.20010318184951.02c6ace0@shell16.ba.best.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <4.3.2.7.2.20010318184951.02c6ace0@shell16.ba.best.com>; from checker@d6.com on Sun, Mar 18, 2001 at 06:58:20PM -0800 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > File handles (channels) are not closed on garbage collection, right > (my tests indicate they're not)? This is correct. > Why is this (just because no > guarantees can be made on when objects will be finalized)? That's one reason. Another reason is that when you have a low-level file descriptor (Unix.file_descr) and build a channel around it (Unix.{in,out}_channel_of_descr), it is often the case that you don't want the file descriptor to be closed when the channel becomes garbage collected -- your code may still be using the file descriptor. > The docs > warn against using finalization routines, so it seems like manually > doing it (or using a wrapper function, which then has to catch and > reraise exceptions) is the only way. I'm not sure which part of the doc you're referring to, but with the new per-object finalization facility of OCaml 3, I think it is safe to do Gc.finalise close_out my_out_channel or Gc.finalise close_in my_in_channel for the channels you'd like to see finalized. - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr