From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 22ABFBC6B for ; Sun, 9 Dec 2007 22:55:05 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIvyW0dA6bjtkGdsb2JhbACPYwIBAQcEBCQH X-IronPort-AV: E=Sophos;i="4.23,274,1194217200"; d="scan'208";a="20148400" Received: from wr-out-0506.google.com ([64.233.184.237]) by mail4-smtp-sop.national.inria.fr with ESMTP; 09 Dec 2007 22:55:04 +0100 Received: by wr-out-0506.google.com with SMTP id c49so1126503wra for ; Sun, 09 Dec 2007 13:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=3HOEqgeWbWs9MUaPcs+5pUEbXGJfH7dSKArMy6Cmdgs=; b=aS6oU7uvIPGpYud2bGvNEy0k3eFo6pt93XoRgzIFt3lZOlBrONJ4LBS25Ft1J3BoKT0laMc6/fMmNiJ7C1djwO0dI/yOG9k1U9J/5QUCU5xmheRpCjIGw3aKrVoyItr2zSoFlxmRPrCFuug0C6ikofR5kKhKaDUO4zxNbjz5qHA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=xFWRsyVQRaNWExUAq3cnJ6LruoUZ4tWf5P7PvHRny6xz7vFO91aoyFsi6vvkZHiCJ081iYmMuSiiRHHPoV+1bhJ4T4g1p6UfGO9ZjmCIY27I7xNwjK4rhRrk1a/AXvvBb1B1Qmzr6GhrT+sKr7uEGVn/rqGbl7OCqvlywlTz3XY= Received: by 10.70.49.1 with SMTP id w1mr5894094wxw.1197237303179; Sun, 09 Dec 2007 13:55:03 -0800 (PST) Received: by 10.90.118.2 with HTTP; Sun, 9 Dec 2007 13:55:03 -0800 (PST) Message-ID: <95513600712091355j35c4fa65g40bbfce02303796a@mail.gmail.com> Date: Sun, 9 Dec 2007 22:55:03 +0100 From: "Olivier Andrieu" Sender: oandrieu@gmail.com To: Fabrice.Pardo@lpn.cnrs.fr Subject: Re: [Caml-list] Ask for a more efficient way to deallocate memory (full version) Cc: caml-list@yquem.inria.fr In-Reply-To: <39980.81.57.198.61.1197236388.squirrel@webmail.lpn.cnrs.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <39980.81.57.198.61.1197236388.squirrel@webmail.lpn.cnrs.fr> X-Google-Sender-Auth: 1dd48f1a1a335d16 X-Spam: no; 0.00; andrieu:01 oandrieu:01 opendir:01 descriptors:01 opendir:01 exn:01 exn:01 wrote:01 unix:01 unix:01 caml-list:01 nerim:01 referenced:02 deallocate:03 let:03 On Dec 9, 2007 10:39 PM, wrote: > Hello, and sorry for my previous unfinished message. > > As the function Unix.opendir returns a value, > we can expect that Unix.closedir will be automatically > called when the dir_handle value is no more referenced. Well, not really: a GC manages memory, not OS resources like file descriptors. I wouldn't recommend relying on the GC to close those kind of resources. Write your code like this: let with_dir fname f = let d = Unix.opendir f in try let r = f d in Unix.closedir d ; r with exn -> Unix.closedir d ; raise exn once the "f" function returns, you directory handle is closed. -- Olivier