caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Exceptions and Gc.
@ 2017-03-20 19:22 Romain Beauxis
  2017-03-21 11:17 ` Dmitry Bely
  0 siblings, 1 reply; 6+ messages in thread
From: Romain Beauxis @ 2017-03-20 19:22 UTC (permalink / raw)
  To: OCaml List

[-- 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 --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-25 11:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-20 19:22 [Caml-list] Exceptions and Gc Romain Beauxis
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

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).