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 LAA06159; Tue, 4 May 2004 11:15:47 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA05584 for ; Tue, 4 May 2004 11:15:46 +0200 (MET DST) Received: from mail0.epfl.ch (mail0.epfl.ch [128.178.50.57]) by nez-perce.inria.fr (8.12.10/8.12.10) with SMTP id i449FjEV014239 for ; Tue, 4 May 2004 11:15:45 +0200 Received: (qmail 23206 invoked by uid 107); 4 May 2004 09:15:45 -0000 Received: from mailav1.epfl.ch (HELO MAILAV1) (128.178.50.190) by mail0.epfl.ch with SMTP; 4 May 2004 09:15:45 -0000 Received: From mail0.epfl.ch ([128.178.50.57]) by MAILAV1 (WebShield SMTP v4.5 MR1a P0803.345); id 1083661923640; Tue, 4 May 2004 11:12:03 +0200 Received: from lcmpc4.epfl.ch (128.178.8.59) by mail0.epfl.ch (AngelmatoPhylax SMTP proxy); Tue, 04 May 2004 11:15:44 +0200 Date: Tue, 4 May 2004 11:15:44 +0200 (CEST) From: Henri DF X-X-Sender: henridf@lcmpc4.epfl.ch To: Ker Lutyn cc: caml-list@inria.fr, Subject: Re: [Caml-list] file descriptor leaks? In-Reply-To: <20040504074648.GA29829@bourg.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 40975F41.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 descriptor:01 basile:01 2004:99 sock:01 descriptor:01 finalization:01 asynchronous:01 kernel:01 kernel:01 ocaml:01 ocaml:01 caml:01 garbage:01 0700,:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk here's a relevant message explaining why ocaml gc doesn't collect file descriptiors: http://caml.inria.fr/archives/200311/msg00264.html By the way , from R. Jones tutorial (chap 9), i saw: Calls to read_file open the file but don't close it. Because OCaml uses a full garbage collector chan isn't collected until some (unknown, asynchronous) time later when the minor heap becomes full. This means that open file descriptors build up waiting to be collected in one go. If files is a long list, then this code is likely to fail when the OS limit on the number of open files is reached. which i guess is inaccurrate? henri On Tue, 4 May 2004, Basile Starynkevitch local wrote: > On Mon, May 03, 2004 at 04:32:32PM -0700, Ker Lutyn wrote: > [...] > > > Assuming f does not close the fd when it's done, [...] is this > > better? > > > > while true do > > let fd, _ = Unix.accept sock in > > let g fd = try f fd; Unix.close fd with e -> Unix.close fd; raise e in > > ignore (Thread.create g fd) > > done > > > > Yes. First, a file descriptor is mostly heavy in the OS kernel side; > inside a process, an fd is just an integer. To free the fd (kernel) > resource, you *have* to call Unix.close (i.e. to call the close(2) > system call). > > Second, there are no implicit call to the close(2) system call inside > the Ocaml system (there used to be, long time ago, implicit close of > channels by the GC. This finalization is gone). > > So yes, every file descriptor you got thru accept has to be explicitly > closed. Some higher level functions in the Unix library happen to do > so. > > ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners