From: Dmitry Bely <dmitry.bely@gmail.com>
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Exceptions and Gc.
Date: Tue, 21 Mar 2017 14:17:05 +0300 [thread overview]
Message-ID: <CAMT7qiReC=tQxPYRkESTYASu=B4LcqaJKPyToCO23f73d8wP7w@mail.gmail.com> (raw)
In-Reply-To: <CABWZ6OQHAzbUr8cmoudwK-irADSwa253iJTcUMbXoa9BD6vFcA@mail.gmail.com>
It has nothing to do with exceptions. The problem is that OCaml
runtime does not execute the garbage collector on program exit. But
you can write
let _ = at_exit Gc.full_major
if you need to force GC.
On Mon, Mar 20, 2017 at 10:22 PM, Romain Beauxis
<romain.beauxis@gmail.com> wrote:
> 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
- Dmitry Bely
next prev parent reply other threads:[~2017-03-21 11:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 19:22 Romain Beauxis
2017-03-21 11:17 ` Dmitry Bely [this message]
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='CAMT7qiReC=tQxPYRkESTYASu=B4LcqaJKPyToCO23f73d8wP7w@mail.gmail.com' \
--to=dmitry.bely@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;
as well as URLs for NNTP newsgroup(s).