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 LAA24653; Tue, 9 Sep 2003 11:32:05 +0200 (MET DST) 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 LAA09702 for ; Tue, 9 Sep 2003 11:32:04 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h899W2f08496; Tue, 9 Sep 2003 11:32:02 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA05613; Tue, 9 Sep 2003 11:32:01 +0200 (MET DST) From: Pierre Weis Message-Id: <200309090932.LAA05613@pauillac.inria.fr> Subject: Re: [Caml-list] GC Question In-Reply-To: <3F5CE84F.4030609@univ-savoie.fr> from Christophe Raffalli at "Sep 8, 103 10:36:31 pm" To: christophe.raffalli@univ-savoie.fr (Christophe Raffalli) Date: Tue, 9 Sep 2003 11:32:01 +0200 (MET DST) Cc: Damien.Doligez@inria.fr, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pierre:01 weis:01 pierre:01 weis:01 caml-list:01 raffalli:01 cristal:01 christophe:01 bindings:01 explicitely:01 afaik:01 behaviour:01 stack:02 explicit:03 data:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > in the following kind code : > > let l = ... a function building a long list ... in > let l' = List.map fn l in (* or fold or anything similar *) > ... no more reference to l ... > > Once the beginning of l has been read to compute l' (assuming List.map > starts from the beginning of l) is the GC able to collect the beginning > of l ? No it cannot since, AFAIK, l is not freed (i.e. assigned to 0) into the stack (or local environment) before you leave the block where your code occurs (normally the activation block of the function where it appears in). > If not how to write the code to ensure this behaviour of the GC ? > > Christophe Raffalli Do not use let bindings, write function applications or function compositions instead. (Instead of writing let l1 = f l0 in let l2 = g l1 in h l2 write let i l = h (g (f l)) in i l0) Alternatively, use explicit references to lists and free them explicitely in your code ! This is tractable when the flow of control of the code is simple enough (for instance in the case of a clear succession of passes where data from previous passes are clearly unused in the following steps). Hope this helps, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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