2017-03-21 6:58 GMT-05:00 Max Mouratov <max.mouratov@outlook.com>:
> Tuesday, March 21, 2017, 12:22:54 AM, Romain wrote:
>> 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..
>
> Tuesday, March 21, 2017, 4:17:05 PM, Dmitry wrote:
>> 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.
>
> It won't guarantee running all finalisers, as some of the objects may
> still be reachable. As part of a yet unmerged patch [1] that will land
> in 4.06, I have added an option that makes the runtime shut down
> properly on process exit (by an implicit call to the new caml_shutdown
> function), but unfortunately it doesn't handle Gc.finalise yet, as the
> relevant logic is not so trivial (and is probably a subject for a
> different PR). However, custom blocks [2] are guaranteed to be
> finalised properly with caml_shutdown, so you might look into this.
Thanks guys.
That patch sounds great. I was just wondering since after all this
time writing OCaml I never thought about it nor actually ready
anything about this topic.
Being able to clean everything up when the program exits seems like a
reasonable feature.
Romain
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs