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,DNS_FROM_SECURITYSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 99A6EBB84 for ; Fri, 31 Oct 2008 16:05:11 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhYEAPO7CknAXQIngWdsb2JhbACUDgEBFiK5aINR X-IronPort-AV: E=Sophos;i="4.33,523,1220220000"; d="scan'208";a="18720269" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 31 Oct 2008 16:05:10 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m9VF58FW003671 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 31 Oct 2008 16:05:10 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnIAAES7CklCbwQbi2dsb2JhbACUDgEBAQoLCgcPBrlfg1E X-IronPort-AV: E=Sophos;i="4.33,523,1220220000"; d="scan'208";a="19427791" Received: from out3.smtp.messagingengine.com ([66.111.4.27]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 Oct 2008 16:05:10 +0100 Received: from compute2.internal (compute2.internal [10.202.2.42]) by out1.messagingengine.com (Postfix) with ESMTP id 4ED4A189ED3; Fri, 31 Oct 2008 11:05:09 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute2.internal (MEProxy); Fri, 31 Oct 2008 11:05:09 -0400 X-Sasl-enc: zD7xdYKBLmYmZokOiSID4UFdewmapbi1dsVpqiFnxY7b 1225465508 Received: from [192.168.1.10] (ALyon-157-1-126-20.w90-42.abo.wanadoo.fr [90.42.21.20]) by mail.messagingengine.com (Postfix) with ESMTPSA id 95DAB5AAC; Fri, 31 Oct 2008 11:05:08 -0400 (EDT) Message-ID: <490B1CDC.8080808@ens-lyon.org> Date: Fri, 31 Oct 2008 15:57:32 +0100 From: Martin Jambon User-Agent: Thunderbird 2.0.0.17 (X11/20081008) MIME-Version: 1.0 To: =?ISO-8859-1?Q?Daniel_B=FCnzli?= Cc: OCaml Mailing List Subject: Re: [Caml-list] understanding weak References: <490A6A19.9050704@ens-lyon.org> <9E14E68C-5480-46B8-9426-11EE40B6B139@erratique.ch> In-Reply-To: <9E14E68C-5480-46B8-9426-11EE40B6B139@erratique.ch> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 490B1EA4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 bunzli:01 ocaml's:01 pointers:01 pointers:01 hash:01 pointer:01 pointer:01 gc'ed:01 warren:98 wrote:01 wrote:01 caml-list:01 int:01 jambon:01 Daniel Bünzli wrote: > > Le 31 oct. 08 à 03:14, Martin Jambon a écrit : > >> Warren Harris wrote: >>> I'd like to understand better how ocaml's weak pointers operate. First, >>> although it doesn't seem to be specified in the documentation, I assume >>> that weak pointers will *not* be reclaimed (e.g. from a weak hash table) >>> if the program retains some other reference to the object. I.e. the weak >>> pointer must be the last remaining pointer to the object for reclamation >>> to occur. >> >> Yes, otherwise the program would crash. > > No since Weak.get returns an option type. As written the documentation > sounds like the binding could disappear from the array even though the > program still has references to the value. This could be done, wouldn't > be usefull, but wouldn't crash the program. let x = (1, 2);; let wa = Weak.create 10;; Weak.set wa 0 (Some x);; ... print_int (fst x);; (fst x) would certainly cause funny effects if x were GC'ed at an arbitrary time after it has been added to the weak array. An object can be reclaimed by the GC only if there is no reference to it. This remains true. Adding an object to a weak array just doesn't count as a reference. Martin -- http://mjambon.com/