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 66139BB84 for ; Fri, 31 Oct 2008 21:18:29 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnIAAJsEC0lCbwQbi2dsb2JhbACUDwEBAQoLCgcPBrlag1E X-IronPort-AV: E=Sophos;i="4.33,524,1220220000"; d="scan'208";a="18730361" Received: from out3.smtp.messagingengine.com ([66.111.4.27]) by mail3-smtp-sop.national.inria.fr with ESMTP; 31 Oct 2008 21:18:28 +0100 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 511A9189326 for ; Fri, 31 Oct 2008 16:18:28 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute1.internal (MEProxy); Fri, 31 Oct 2008 16:18:28 -0400 X-Sasl-enc: AdSjFdOoqRxks3FsK/8GOMHykSDfqQbKbI+sUrGPA3fn 1225484307 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 C61752E7DC for ; Fri, 31 Oct 2008 16:18:27 -0400 (EDT) Message-ID: <490B664C.7000209@ens-lyon.org> Date: Fri, 31 Oct 2008 21:10:52 +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 val:01 val:01 bool:01 wrote:01 wrote:01 clearer:01 caml-list:01 pair:01 int:01 int:01 jambon:01 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. OK. I think now I understand the question :-) And we all agree that the documentation could be clearer. What I'm wondering is why there is one Weak.set function that takes an option as argument rather than a pair Weak.set/Weak.clear. What is certain is that some (re)boxing is done by Weak.get: # let a = Weak.get wa 0;; val a : (int * int) option = Some (1, 2) # let b = Weak.get wa 0;; val b : (int * int) option = Some (1, 2) # a == b;; - : bool = false Of course it doesn't tell whether the original (Some x) is stored as-is but copied by Weak.get or if x is stored unwrapped. I think I'll just take a look at the implementation. That can only be a good thing. Martin -- http://mjambon.com/