From: ygrek <ygrekheretix@gmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Finding memory leakage using Gc module
Date: Wed, 1 Jun 2011 22:09:27 +0300 [thread overview]
Message-ID: <20110601220927.84d72f80.ygrekheretix@gmail.com> (raw)
In-Reply-To: <BANLkTinhF659qw5YNYU3Pn524fxjXMKVYw@mail.gmail.com>
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
prev parent reply other threads:[~2011-06-01 19:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-01 12:40 Hans Ole Rafaelsen
2011-06-01 19:09 ` ygrek [this message]
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=20110601220927.84d72f80.ygrekheretix@gmail.com \
--to=ygrekheretix@gmail.com \
--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