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
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: -- (:)
From: Frederic van der Plancke <fvdp@d...>
Subject: Re: [Caml-list] Memory usage/ garbage collection question

Richard Jones wrote:
> On Fri, Oct 14, 2005 at 04:58:59AM -0500, Seth J. Fogarty wrote:
> > I do not see why iterating through a list that consumed a lot of
> > memory should (innately) cause you to thrash. What is thrashing?
> > access to the disk? Garbage collection?
> That's where I'm not really sure, except that it is observably
> thrashing.  Since it's a simple iteration, I guess that would
> implicate the GC?
> > No, because you have bound rows to a name. Now, I believe if rows is
> > returned by a function, and is NOT bound by name in that function, it
> > can be garbage collected. I.E.
> Ah OK ... I'm interested though: why does binding a value to a name
> cause problems?  Surely at this level (ocamlopt generated code) there
> ought to be no difference between a named value and an unnamed one?
> Rich.

Perhaps the problem is not the name, but the fact that when you write

    List.iter f rows

the compiler isn't going to go great lengths in optimizing out the reference to rows before the call to List.iter, since the optimisation probably isn't free and the compiler (and compiler writers) don't know in advance how worthwhile it would be.

If the call to List.iter was a tail call the compiler would probably be forced to optimise rows out.

Hence my 0.02 cents worth untested idea: you might try and use tail call optimisation to get rid of that reference.

   let do_work () = 
      let rows = ... in
      List.iter (...) rows