From: Romain Beauxis <romain.beauxis@gmail.com>
To: OCaml List <caml-list@inria.fr>
Subject: [Caml-list] Exceptions and Gc.
Date: Mon, 20 Mar 2017 14:22:54 -0500 [thread overview]
Message-ID: <CABWZ6OQHAzbUr8cmoudwK-irADSwa253iJTcUMbXoa9BD6vFcA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 859 bytes --]
Hi guys,
Apologies if I'm beating a dead horse but I think I've never wondered about
this: What are the assumptions related to the garbage collector when an
exception is raised?
I sort-of always assumed it would be run but it doesn't seem that this is
the case. This code:
let () =
let g () =
let f _ =
Printf.printf "Collecting x\n%!"
in
let x = Bytes.create 1024 in
Gc.finalise f x;
()
in
g ();
Gc.full_major();
raise Not_found
Shows that the finalization function is never call if I remove the call to
full_major. Any reason for that?
The reason I'm asking if that I know I've been writing C bindings where
some cleanup operations are wrapped up in the finalization code with the
expectation that, except for a hard crash, it would always be executed at
some point in the future..
Thanks for y'all comments!
Romain
[-- Attachment #2: Type: text/html, Size: 1194 bytes --]
next reply other threads:[~2017-03-20 19:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 19:22 Romain Beauxis [this message]
2017-03-21 11:17 ` Dmitry Bely
2017-03-21 11:58 ` Max Mouratov
2017-03-21 15:07 ` Romain Beauxis
2017-03-21 16:05 ` Gabriel Scherer
2017-03-25 11:11 ` SP
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=CABWZ6OQHAzbUr8cmoudwK-irADSwa253iJTcUMbXoa9BD6vFcA@mail.gmail.com \
--to=romain.beauxis@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