Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Memory usage/ garbage collection question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-10-14 (09:36)
From: yoann padioleau <padator@w...>
Subject: Re: [Caml-list] Memory usage/ garbage collection question

> 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.

Because rows is still accessible after the List.iter  so it is normal that it is not garbage collected.

I had the same kind of problem and to optimize it I choose to produce the elements of rows lazily
(but then I had another problem with the Lazy modudle where elements were not garbage collected so 
I use my own lazy module (simple via closure) and it works perfectly well).

> Rich.
> -- 
> Richard Jones, CTO Merjis Ltd.
> Merjis - web marketing and technology -
> Team Notepad - intranets and extranets for business -
> _______________________________________________
> Caml-list mailing list. Subscription management:
> Archives:
> Beginner's list:
> Bug reports: