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.3 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 DA463BB84 for ; Fri, 31 Oct 2008 21:52:17 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnIAANAMC0lCbwQbi2dsb2JhbACUDwEBAQoLCgcPBrl+g1E X-IronPort-AV: E=Sophos;i="4.33,524,1220220000"; d="scan'208";a="18731023" Received: from out3.smtp.messagingengine.com ([66.111.4.27]) by mail3-smtp-sop.national.inria.fr with ESMTP; 31 Oct 2008 21:52:17 +0100 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id A891218A2B2 for ; Fri, 31 Oct 2008 16:52:16 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Fri, 31 Oct 2008 16:52:16 -0400 X-Sasl-enc: RY9GA+uOjchKTQxuoNpYcfQVNVJx9oV1G8hhXcqecPZR 1225486336 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 23492108E4 for ; Fri, 31 Oct 2008 16:52:16 -0400 (EDT) Message-ID: <490B6E38.5060505@ens-lyon.org> Date: Fri, 31 Oct 2008 21:44:40 +0100 From: Martin Jambon User-Agent: Thunderbird 2.0.0.17 (X11/20081008) MIME-Version: 1.0 To: OCaml Mailing List Subject: Re: [Caml-list] understanding weak References: <490A6A19.9050704@ens-lyon.org> <9E14E68C-5480-46B8-9426-11EE40B6B139@erratique.ch> <490B1CDC.8080808@ens-lyon.org> <490B58BA.6090307@metaprl.org> In-Reply-To: <490B58BA.6090307@metaprl.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 gc'ed:01 gced:01 orphaned:01 unboxed:01 pointer:01 wrote:01 wrote:01 caml-list:01 int:01 jambon:01 jambon:01 arbitrary:02 ambiguous:02 let:03 Aleksey Nogin wrote: > On 31.10.2008 07:57, Martin Jambon wrote: > >> 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, > > You are answering the wrong question - you are answering "could x be > GCed too early?" - the answer is obviously "no". However, the initial > question was "could (Some x) be removed from wa too early by GC - before > x is orphaned?" The answer is "we'd hope not", but the documentation is > somewhat ambiguous. So I checked the implementation and it turns out that x is unboxed from (Some x) before being added to the weak array. x is really the value that matters and of course not keeping any reference to (Some x) has no importance. The weak pointer is x (or a null value), stored as a cell of the weak array. Martin -- http://mjambon.com/