caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jérémie Dimino" <jeremie@dimino.org>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: Gerd Stolpmann <info@gerd-stolpmann.de>, Lauri Alanko <la@iki.fi>,
	caml-list@inria.fr
Subject: Re: [Caml-list] Channels not closed on gc?
Date: Tue, 29 May 2012 14:49:47 +0200	[thread overview]
Message-ID: <20120529144947.605213ae@caladan.esterel-technologies.com> (raw)
In-Reply-To: <87fwajtciw.fsf@frosties.localnet>

Le Tue, 29 May 2012 14:08:55 +0200,
Goswin von Brederlow <goswin-v-b@web.de> a écrit :

> If your channel is a pipe and you need it to stay open then keep it
> alive. If you need to control when it is closed than close it when you
> want it to be close, which you can only do as long as it stays alive.
> 
> So this argument is realy not an argument.
> 
> Note that nobody suggested restricting closing of channels to just the
> GC. Only to have the GC double check and close them before they leak.
> If you do it right then nothing changes. But if you did it wrong the
> GC will catch that.

Sometimes you have a file descriptor and you temporary create a
channel for it. Once you are done with the channel you flush it (if it
is an output channel) but you do not close it and continue to use the
file descriptor. In this case automatically closing the channel (and
so the underlying file descriptor) would be wrong.

> Lets compare this feature to boundary checks for strings and arrays.
> In correct code they are completly and utterly pointless since we
> know all our access remains within bounds. Still we do check because
> we know that not all code is correct.
> 
> Same with channels (and Unix.file_descr). If your code is correct and
> you properly close them all correctly it is pointless for the GC to
> check and close them. But still this should be done to catch those
> cases where the programmer forgot about it. And this check would be a
> lot cheaper than boundary checks. It only checks once on destruction.
> 
> And I agree that such a case should output a warning because people
> should not start to assume the GC will close the channel, it doesn't
> do so determnistically nor when the program terminates. Not closing a
> channel is a resource mismanagement in the code so te code should be
> fixed. The GC should just help to spot such cases.

Not if you consider that a buffered channel is just an helper data
structure on top of a read/write function.

Cheers,

-- 
Jérémie

      parent reply	other threads:[~2012-05-29 12:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-21 11:23 Lauri Alanko
2012-05-21 11:57 ` AW: " Gerd Stolpmann
2012-05-21 12:53   ` Philippe Wang
2012-05-21 13:31     ` Gerd Stolpmann
2012-05-21 14:18       ` Philippe Wang
2012-05-21 14:48         ` Mehdi Dogguy
2012-05-29 12:08   ` AW: " Goswin von Brederlow
2012-05-29 12:46     ` Gerd Stolpmann
2012-05-29 14:13       ` oliver
2012-05-29 18:39         ` Török Edwin
2012-05-29 18:58           ` Philippe Veber
2012-05-29 12:49     ` Jérémie Dimino [this message]

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=20120529144947.605213ae@caladan.esterel-technologies.com \
    --to=jeremie@dimino.org \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=info@gerd-stolpmann.de \
    --cc=la@iki.fi \
    /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).