From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id B86B87ED1A for ; Mon, 21 May 2012 14:53:18 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmMKACk6uk/RVda2kGdsb2JhbAA6CqUYjmAIIgEBAQEJCQ0HFAQjghUBAQEEEgIsATgBAwwBBQULAwouIhIBBQEcBhMih14DC6ByCQOPFIUCJw2JTAEFDIp5DwqFNAONFYgGjhU9gVOCNoFd X-IronPort-AV: E=Sophos;i="4.75,631,1330902000"; d="scan'208";a="144495384" Received: from mail-ob0-f182.google.com ([209.85.214.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-MD5; 21 May 2012 14:53:18 +0200 Received: by obcni5 with SMTP id ni5so15206125obc.27 for ; Mon, 21 May 2012 05:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=467Ti8VwrpPrg+QM04Z5EKOD1bUfKl039ReaVEoQmYo=; b=oMmzshw0h6Ha7kksYHGKFwJ2a7v7SBHnsSuTnrsbrofpZocaAvvaV1RHe3AwdOqWD4 owNUkWqbqxiR3a6SC8kg0Yk8U9hT/ddPf4X3RPfaIozW4hWzAY/ES2Azy4Oc995pv4SM FWaHScBX3xNRQN5O8ArG5pc2Yg65+I2O7oNFYMScF7TXCgR8DLET1qa5kZsCAPeyZhtJ 6fRGSgte/zIPhvkfODqj1E2LM/9SqryS/ZiPVDdLWgQYf2vk7M/jfPaularA5obJEFMt +6VkslGnu6hcQeP+nky5Wy4VzD9GRR7r/KsRQ/YlfqJzKcTivgmzP+5pzCQjG4e/g4V+ ipXw== MIME-Version: 1.0 Received: by 10.182.12.6 with SMTP id u6mr19676002obb.12.1337604794998; Mon, 21 May 2012 05:53:14 -0700 (PDT) Sender: philippe.wang.lists@gmail.com Received: by 10.182.60.193 with HTTP; Mon, 21 May 2012 05:53:14 -0700 (PDT) In-Reply-To: <1337601452.19263.0@samsung> References: <20120521142336.79901oeoxunjuoc8.lealanko@webmail.helsinki.fi> <1337601452.19263.0@samsung> Date: Mon, 21 May 2012 14:53:14 +0200 X-Google-Sender-Auth: VP3xHyJDa_kLHgQCY-z-iIkcDow Message-ID: From: Philippe Wang To: Gerd Stolpmann Cc: Lauri Alanko , caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Channels not closed on gc? On Mon, May 21, 2012 at 1:57 PM, Gerd Stolpmann wr= ote: > Am 21.05.2012 13:23:36 schrieb(en) Lauri Alanko: > >> I only recently noticed that ocaml does not close open channels when they >> are garbage collected. This is evidently intentional behavior, but it was >> quite unexpected. >> >> To be clear, I do think it's bad style to rely on GC for releasing OS >> resources, but that doesn't explain why GC shouldn't do this if the >> programmer has failed to explicitly close the channel. And if the intent= ion >> were to _enforce_ good style, the channel finaliser would spout out an e= rror >> or warning upon detecting that the channel hasn't yet been closed, inste= ad >> of just silently leaking file handles like it does currently. >> >> It is of course trivial to "fix" this by attaching a simple finaliser, b= ut >> the fact that this is not done by default makes me suspect that there wo= uld >> be something fishy with this approach. So, what's the rationale for the >> current behavior? > > > It's predictable. > > Closing a channel is not only about releasing OS resources. Imagine the > channel is actually a pipe - closing it means to signal EOF, i.e. it's a = way > of notifying another program about an event. This should not happen behind > one's back. > > Closing a regular file would in deed be harmless, but there is no generic > way to identify such channels (in the OS). > > Gerd > > >> Thanks, >> >> >> Lauri Wouldn't it be a good idea to provide both ways? i.e., one that collects automatically, in addition to the current one that doesn't. --=20 Philippe Wang =A0=A0 mail@philippewang.info