Browse thread
Memory usage/ garbage collection question
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | skaller <skaller@u...> |
| Subject: | Re: [Caml-list] Memory usage/ garbage collection question |
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 <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net