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