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
[Caml-list] memory problems
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-08-19 (20:13)
From: Tahir H Butt <tahir@a...>
Subject: [Caml-list] memory problems
Hi all,

There seems to be something going screwy in a piece of my code. The code
is used to average a matrix of values over several modifications. 

  for r=0 to k-1 do
    let matrix_r = matrix.(r) in
    let f_r = feature_vals.(r) in
    for j=0 to n-1 do
      let f_rj = f_r.(j) in
      let matrix_rj = matrix_r.(j) in
      let current_sum = f_rj.current_sum in
      let generation = f_rj.generation in
      let new_sum = current_sum +. 
        (matrix_rj *. (float_of_int (generation_counter -
      (* VARIED SECTION *)
      f_rj.generation <- generation_counter

	(A) f_rj.current_sum <- current_sum;
	(B) f_rj.current_sum <- 1.0;
	(C) f_rj.current_sum <- new_sum;

Using both ocamlopt and ocamlc (3.06, and 3.07beta1, with and without
optimization flags), (A) and (B) keep a constant memory load through the
course of the program. (C) which is the actual value I need to set
causes the memory usage to grow each time the above function is called.

I've tried throwing in some Gc.compact() lines, without luck.

This is mildly frustrating. Is this a bug, or a mistake on my part? I
can send whoever wishes to see the rest of the code the source, but it's
probably not critical here. I tried replicating this as an isolated
case, and it didn't seem to cause problems. 

Any ideas? Has someone reported a similar bug? I tried searching the BTS
without luck.

Sorry if this might be of trivial concern, but I'm far from an expert of
the ocaml language.

Here is some Gc.stat info, before and after the code above, as well as
with Gc.compact() (all with ocaml-3.07beta1)

% Before function
minor_words: 108910518
promoted_words: 36319417
major_words: 67201780
minor_collections: 4947
major_collections: 10
heap_words: 69238784
heap_chunks: 598
top_heap_words: 69238784
live_words: 66342960
live_blocks: 11447005
free_words: 2895824
free_blocks: 89
largest_free: 61440
fragments: 0
compactions: 1
% After function
minor_words: 141302822
promoted_words: 67223235
major_words: 98105598
minor_collections: 7505
major_collections: 11
heap_words: 97255424
heap_chunks: 1054
top_heap_words: 97255424
live_words: 97246778
live_blocks: 21747585
free_words: 8646
free_blocks: 43
largest_free: 8562
fragments: 0
compactions: 1
% After function and compact
minor_words: 141303588
promoted_words: 67223235
major_words: 98106033
minor_collections: 7505
major_collections: 13
heap_words: 97255424
heap_chunks: 1054
top_heap_words: 97255424
live_words: 95698876
live_blocks: 21232921
free_words: 1556548
free_blocks: 67
largest_free: 61440
fragments: 0
compactions: 2


Tahir H Butt
Brown University
Cognitive and Linguistic Sciences
PhD Student

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: