From: Alain Frisch <alain@frisch.fr>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: Loup Vaillant <loup.vaillant@gmail.com>,
ocaml-users@janestcapital.com,
Caml mailing list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] The GC is not collecting... my mistake?
Date: Wed, 07 Nov 2007 10:42:59 +0100 [thread overview]
Message-ID: <473188A3.4010809@frisch.fr> (raw)
In-Reply-To: <f8560b80711060931h20702a72j918c1f857faa78e1@mail.gmail.com>
Markus Mottl wrote:
> If you compile this to native code, running "foo 1" will print "1"
> followed by "2". If you run "foo 2" it will print "1", then
> "finalized", then "2". Byte code will only print "1" and "2" in any
> case - hm, weird.
For bytecode, this is an expected behavior: the back-end does not emit
any information that would allow the runtime system to know which value
on the stack is still live (at each possible GC point). The behavior in
native code is an optimization which lets the GC reclaim more memory,
but AFAIK, this is not specified. The safe assumption is that a value
identifier forces the value to remain live in all its syntactic scope
(this is not a formal definition; for instance, a tail call terminates
the scope of identifiers defined at the call site).
> Obviously, OCaml does not reclaim the tuple during the allocation loop
> even though it could (and IMHO should). This can introduce
> substantial space leaks as happened to us.
I agree this might be surprising, but since I don't see the behavior
changing for bytecode anyway, I don't think it is worth dealing with
this case in native code (any program that relies on the improved
behavior you ask for would have an unexpected behavior in bytecode).
The proper solution might be to reflect in the syntactic scope your
desire to see some value reclaimed:
let main2 () =
let b =
let a, b = alloc () in
Gc.finalise finaliser a;
print_len a;
b
in
(* Here a is no longer visible and can thus be reclaimed. *)
alloc_loop ();
print_len b
This works in bytecode as well.
Alain
next prev parent reply other threads:[~2007-11-07 9:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-06 12:51 Loup Vaillant
2007-11-06 14:46 ` [Caml-list] " Dominique Martinet
2007-11-06 17:31 ` Markus Mottl
2007-11-07 9:13 ` Loup Vaillant
2007-11-07 9:42 ` Alain Frisch [this message]
2007-11-07 15:36 ` Markus Mottl
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=473188A3.4010809@frisch.fr \
--to=alain@frisch.fr \
--cc=caml-list@yquem.inria.fr \
--cc=loup.vaillant@gmail.com \
--cc=markus.mottl@gmail.com \
--cc=ocaml-users@janestcapital.com \
/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