Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Ohad Rodeh <orodeh@cs.huji.ac.il>
To: Ocaml Mailing List <caml-list@inria.fr>
Subject: Garbage collection qustion
Date: Mon, 29 Jun 1998 10:51:27 +0300 (IDT)	[thread overview]
Message-ID: <Pine.BSI.3.96.980629104958.9935g-100000@hamster.cs.huji.ac.il> (raw)

Hi,
  I have a problem with the Ocaml garbage collector. The included program
allocates memory from the heap and does nothing with it. The heap keeps
growing without bound although memory is not being used and no refrences
to it exist. 

Running the program with the following parameters:
	ttt -nrounds 1000 -status 3 -chunk 10000

Will go through 1000 rounds of allocating a string of size 10000. The
status flag describes how many GC status reports you would like. 

Why does the heap grow without bound? 
	Ohad.
-------------------------------

(*ttt.ml 
*)
open Printf

let nrounds = ref 100
let status = ref 10
let chunk  = ref 1000

(* Status of the heap
*)
let string_list_of_gc_stat s =
  let alloc_promote_pct = (s.Gc.promoted_words * 100) / s.Gc.minor_words in
  let alloc_major_direct = s.Gc.major_words - s.Gc.promoted_words in
  let blocks_total = s.Gc.live_blocks + s.Gc.free_blocks in
  let blocks_live_pct = (s.Gc.live_blocks * 100) / blocks_total in
  let words_live_pct = (s.Gc.live_words * 100) / s.Gc.heap_words in
  [ sprintf "allocation: minor=%.1fM (%d%% promoted) (direct major=%dK)" 
    ((float s.Gc.minor_words) /. 1000000.0) alloc_promote_pct (alloc_major_direct/1000) ;
    sprintf "collections: minor=%d, major=%d, compact=%d" s.Gc.minor_collections s.Gc.major_collections s.Gc.compactions ;
    sprintf "words: %d (%d%% live) (%d chunks)" s.Gc.heap_words words_live_pct s.Gc.heap_chunks ;
    sprintf "blocks: %d (%d%% live) (largest_free=%d)" blocks_total blocks_live_pct s.Gc.largest_free
  ]	

let string_of_list f l   = sprintf "[%s]" (String.concat "|" (List.map f l))

(* Print the heap status?
*)
let chp i =  
	if (i mod (!nrounds / !status) = 0) then (
		let stat = Gc.stat () in
		printf "%s\n" (string_of_list (fun x -> x) (string_list_of_gc_stat stat));
		Gc.minor();
		Gc.major()
	)

let _ = 
 Arg.parse [
	"-nrounds",Arg.Int(fun i -> nrounds := i), "nrounds";
	"-status",Arg.Int(fun i -> status := i), "How may heap status reports";
	"-chunk",Arg.Int(fun i -> chunk := i), "The size of string allocated in each round";
  ] (fun _  -> ()) "perf-crypto";

  let r = Gc.get () in    
	r.Gc.verbose <- true;    
	Gc.set r;

	for i=0 to !nrounds do 
		chp i;
		let cccc = String.create !chunk in ()
	done








             reply	other threads:[~1998-06-29 18:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-29  7:51 Ohad Rodeh [this message]
1998-07-01  9:26 Damien Doligez
1998-07-02  8:09 ` Ohad Rodeh
1998-07-03 14:20 Damien Doligez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.BSI.3.96.980629104958.9935g-100000@hamster.cs.huji.ac.il \
    --to=orodeh@cs.huji.ac.il \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox