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