From: Jim Pryor <lists+caml@jimpryor.net>
To: caml-list@inria.fr
Subject: [Caml-list] memory leak in toplevel? or, how to implement sizeof
Date: Thu, 6 Jan 2011 08:05:39 -0500 [thread overview]
Message-ID: <20110106130539.GB12229@vaio.hsd1.pa.comcast.net> (raw)
Starting up the toplevel fresh, with no .ocamlinit file, I see this:
$ /usr/bin/ocaml
Objective Caml version 3.12.0
# Gc.(compact();counters());;
- : float * float * float = (79217., 32932., 82668.)
# Gc.(compact();counters());;
- : float * float * float = (93530., 32932., 85816.)
# Gc.(compact();counters());;
- : float * float * float = (107843., 32932., 88964.)
Why do both the minor_words and major_words keep climbing? Do these
indicate the number of words _ever_ allocated, and so the overhead of
doing the garbage collection and compacting has pushed them up? Or do
they indicate the number of words _now_ allocated, so the fact that they
continue to climb indicates something is leaking memory?
Omitting the collection, I still see persisting climbs:
$ /usr/bin/ocaml
Objective Caml version 3.12.0
# Gc.(counters());;
- : float * float * float = (227355., 69894., 150533.)
# Gc.(counters());;
- : float * float * float = (240969., 73385., 154024.)
# Gc.(counters());;
- : float * float * float = (254583., 73385., 154024.)
Two questions:
1. Is there anything here to be worried about? A memory leak that needs
to be tracked down? (If so, won't in be in the toplevel or some other
piece of the core system? I haven't loaded any other libraries.) Or is
there nothing to worry about?
2. What bit of the Gc should I poll to find out how much memory I just
allocated? I was trying to write a function like this:
let sizeof maker =
let baseline = get_baseline_from_gc () in
let res = maker () in
let final = get_final_from_gc () in
(final -. baseline, res);;
This post at the Jane Street blog
<http://ocaml.janestreet.com/?q=node/30> suggests (among other things)
that:
# (Gc.stat()).Gc.minor_words;;
is the right way to poll the Gc. However:
# (Gc.stat()).Gc.minor_words;;
- : float = 226623.
# (Gc.stat()).Gc.minor_words;;
- : float = 229632.
# (Gc.stat()).Gc.minor_words;;
- : float = 232641.
# let a = Some 1;;
val a : int option = Some 1
# (Gc.stat()).Gc.minor_words;;
- : float = 242131.
# (Gc.stat()).Gc.minor_words;;
- : float = 245140.
says there are 9 words allocated just for each poll of the Gc, and
then 9490 (!) words allocated for the `Some 1`. Something is amiss.
--
Jim Pryor
profjim@jimpryor.net
next reply other threads:[~2011-01-06 13:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-06 13:05 Jim Pryor [this message]
2011-01-06 14:20 ` David Allsopp
2011-01-06 14:44 ` Jim Pryor
2011-01-06 14:59 ` Jim Pryor
2011-01-07 12:25 ` Damien Doligez
2011-01-07 14:14 ` Jim Pryor
2011-01-07 14:22 ` dmitry grebeniuk
2011-01-06 15:05 ` Pascal Zimmer
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=20110106130539.GB12229@vaio.hsd1.pa.comcast.net \
--to=lists+caml@jimpryor.net \
--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