caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] faq? gc'd channels & finalize?
@ 2001-03-19  2:58 Chris Hecker
  2001-03-19 10:49 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Hecker @ 2001-03-19  2:58 UTC (permalink / raw)
  To: caml-list


This must be an FAQ, but I can't find anything about it in the FAQ, the docs, and only a few messages on the caml list early last year...

File handles (channels) are not closed on garbage collection, right (my tests indicate they're not)?  Why is this (just because no guarantees can be made on when objects will be finalized)?  The docs warn against using finalization routines, so it seems like manually doing it (or using a wrapper function, which then has to catch and reraise exceptions) is the only way.

Chris

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] faq? gc'd channels & finalize?
  2001-03-19  2:58 [Caml-list] faq? gc'd channels & finalize? Chris Hecker
@ 2001-03-19 10:49 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2001-03-19 10:49 UTC (permalink / raw)
  To: Chris Hecker; +Cc: caml-list

> File handles (channels) are not closed on garbage collection, right
> (my tests indicate they're not)?

This is correct.

> Why is this (just because no
> guarantees can be made on when objects will be finalized)?

That's one reason.  Another reason is that when you have a low-level
file descriptor (Unix.file_descr) and build a channel around it
(Unix.{in,out}_channel_of_descr), it is often the case that you don't
want the file descriptor to be closed when the channel becomes garbage
collected -- your code may still be using the file descriptor.

> The docs
> warn against using finalization routines, so it seems like manually
> doing it (or using a wrapper function, which then has to catch and
> reraise exceptions) is the only way.

I'm not sure which part of the doc you're referring to, but with the
new per-object finalization facility of OCaml 3, I think it is safe
to do
        Gc.finalise close_out my_out_channel
or
        Gc.finalise close_in my_in_channel

for the channels you'd like to see finalized.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2001-03-19 10:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-19  2:58 [Caml-list] faq? gc'd channels & finalize? Chris Hecker
2001-03-19 10:49 ` Xavier Leroy

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