From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 9FD4FBB81 for ; Fri, 14 Oct 2005 12:03:34 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j9EA3Ybv023028 for ; Fri, 14 Oct 2005 12:03:34 +0200 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 MAA11799 for ; Fri, 14 Oct 2005 12:03:33 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j9EA3ViS023016 for ; Fri, 14 Oct 2005 12:03:32 +0200 Received: from rosella (ppp2-148.lns1.syd7.internode.on.net [59.167.2.148]) by smtp1.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id j9EA2sF5066223; Fri, 14 Oct 2005 19:33:17 +0930 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] Memory usage/ garbage collection question From: skaller To: Richard Jones Cc: caml-list@inria.fr In-Reply-To: <20051014094948.GA11039@furbychan.cocan.org> References: <20051014094948.GA11039@furbychan.cocan.org> Content-Type: text/plain Date: Fri, 14 Oct 2005 20:02:54 +1000 Message-Id: <1129284174.25800.82.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 434F8276.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 434F8273.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 garbage:01 optimise:01 iteration:01 iteration:01 iter:01 stdlib:01 iter:01 garbage:01 iterated:01 rec:01 wrote:01 sourceforge:01 tail:01 match:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Fri, 2005-10-14 at 10:49 +0100, Richard Jones wrote: > I'm trying to optimise a program which is using a large amount of > memory and consequently thrashing. > > The core of the program is an iteration over a list of something like > a million elements which consumes about 1/2 gig of RAM. The iteration > is: > > List.iter ( > fun row -> > (* put row into database and forget about it *) > ) rows; > (* no further references to rows after this *) > > This is the stdlib implementation of List.iter. Should the garbage > collector be able to collect the part of the list which has been > iterated over, during the iteration? At the moment it doesn't look > like it's doing so. let rows = ref [] in (* build up the list of rows here *) let rec doit rows = match rows with | [] -> () | h :: t -> install_in_db h; doit t (* tail call *) in doit (let r = !rows in rows := []; r) -- John Skaller Felix, successor to C++: http://felix.sf.net