From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA02363 for caml-redistribution; Mon, 29 Jun 1998 20:31:37 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA19772 for ; Mon, 29 Jun 1998 09:51:37 +0200 (MET DST) Received: from cs.huji.ac.il (cs.huji.ac.il [132.65.16.10]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id JAA17663 for ; Mon, 29 Jun 1998 09:51:33 +0200 (MET DST) Received: from hamster.cs.huji.ac.il ([132.65.200.30] ident=orodeh) by cs.huji.ac.il with esmtp (Exim 1.950 #1) for caml-list@inria.fr id 0yqYik-0006aI-00; Mon, 29 Jun 1998 10:51:26 +0300 Received: from localhost (orodeh@localhost) by hamster.cs.huji.ac.il (8.8.5/1.1c) with SMTP id KAA28034 for ; Mon, 29 Jun 1998 10:51:27 +0300 (IDT) X-Authentication-Warning: hamster.cs.huji.ac.il: orodeh owned process doing -bs Date: Mon, 29 Jun 1998 10:51:27 +0300 (IDT) From: Ohad Rodeh To: Ocaml Mailing List Subject: Garbage collection qustion Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis 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