caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Finding memory leakage using Gc module
@ 2011-06-01 12:40 Hans Ole Rafaelsen
  2011-06-01 19:09 ` ygrek
  0 siblings, 1 reply; 2+ messages in thread
From: Hans Ole Rafaelsen @ 2011-06-01 12:40 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]

Hi,

is there some way to monitor memory being allocated (and still in use) when
calling a function? In the first case below it should report close to 0 and
in the second close to 10240. But here it reports 10368 in both cases.
Gc.allocated_bytes seems to report allocated bytes without reporting what it
was able to free. Have also tried other Gc functions such as Gc.counters. Is
it some way to find out which bytes have been allocated and not freed after
calling a function? Is there some good methods that people use to find out
(get a hint of) which memory is leaking?

First:
        let str = ref "" in
        Gc.full_major ();
        let before = Gc.allocated_bytes () in
        str := String.create 10240;
        str := "";
        Gc.full_major ();
        let after = Gc.allocated_bytes () in
        let delta = after -. before in
        Printf.printf "Bytes used: %f\n%!" delta;

Second:
        Gc.full_major ();
        let before = Gc.allocated_bytes () in
        str := String.create 10240;
        Gc.full_major ();
        let after = Gc.allocated_bytes () in
        let delta = after -. before in
        Printf.printf "Bytes used: %f\n%!" delta;


Regards,

Hans Ole Rafaelsen

[-- Attachment #2: Type: text/html, Size: 1345 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Finding memory leakage using Gc module
  2011-06-01 12:40 [Caml-list] Finding memory leakage using Gc module Hans Ole Rafaelsen
@ 2011-06-01 19:09 ` ygrek
  0 siblings, 0 replies; 2+ messages in thread
From: ygrek @ 2011-06-01 19:09 UTC (permalink / raw)
  To: caml-list

On Wed, 1 Jun 2011 14:40:06 +0200
Hans Ole Rafaelsen <hrafaelsen@gmail.com> wrote:

> Hi,
> 
> is there some way to monitor memory being allocated (and still in use) when
> calling a function? In the first case below it should report close to 0 and
> in the second close to 10240. But here it reports 10368 in both cases.
> Gc.allocated_bytes seems to report allocated bytes without reporting what it
> was able to free. Have also tried other Gc functions such as Gc.counters. Is
> it some way to find out which bytes have been allocated and not freed after
> calling a function? Is there some good methods that people use to find out
> (get a hint of) which memory is leaking?

Using full_major (to empty minor heap) and looking at live_words works :

open Gc

let str = ref ""

let f () =
        full_major ();
        let before = (stat ()).live_words in
        str := String.create 102400;
        str := "";
        Gc.full_major ();
        let after = (stat ()).live_words in
        let delta = after - before in
        Printf.printf "Words used: %d\n%!" delta

let g () =
        Gc.full_major ();
        let before = (stat ()).live_words in
        str := String.create 102400;
        Gc.full_major ();
        let after = (stat ()).live_words in
        let delta = after - before in
        Printf.printf "Words used: %d\n%!" delta

-- 
 ygrek
 http://ygrek.org.ua

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-01 19:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-01 12:40 [Caml-list] Finding memory leakage using Gc module Hans Ole Rafaelsen
2011-06-01 19:09 ` ygrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).