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.0 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id A11E5BB84 for ; Fri, 31 Oct 2008 00:06:35 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsAAAD/aCUnUGyodkWdsb2JhbACUCwEBAQEJCwoHEQO3HoNR X-IronPort-AV: E=Sophos;i="4.33,518,1220220000"; d="scan'208";a="19404789" Received: from smtp3-g19.free.fr ([212.27.42.29]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 Oct 2008 00:06:35 +0100 Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp3-g19.free.fr (Postfix) with ESMTP id 3A2C117B540; Fri, 31 Oct 2008 00:06:35 +0100 (CET) Received: from [192.168.0.3] (rke75-3-82-229-183-156.fbx.proxad.net [82.229.183.156]) by smtp3-g19.free.fr (Postfix) with ESMTP id E568A17B528; Fri, 31 Oct 2008 00:06:34 +0100 (CET) Message-ID: <490A3DF9.5010700@frisch.fr> Date: Fri, 31 Oct 2008 00:06:33 +0100 From: Alain Frisch User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Warren Harris Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] RE: understanding weak References: <20081030182019.EEBC5BBB7@yquem.inria.fr> <5EFD4D7AC6265F4D9D3A849CEA9219191AB114@LAXA.intra.cea.fr> <8C745AFA-4FC2-4574-AB97-98321ECC4964@gmail.com> In-Reply-To: <8C745AFA-4FC2-4574-AB97-98321ECC4964@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; frisch:01 frisch:01 cuoq:01 cuoq:01 pointers:01 hash:01 ocaml:01 warren:98 wrote:01 wrote:01 caml-list:01 cea:01 short:01 alain:01 alain:01 Warren Harris wrote: > On Oct 30, 2008, at 11:48 AM, CUOQ Pascal - Pascal.CUOQ@cea.fr wrote: >> In short: don't use weak pointers to make >> caches. > > Thanks for the advice -- but I thought this was exactly what weak hash > tables were intended for. Although there is some similarity between a weak table and a cache ("store values, but feel free to get rid of them"), they are really different beasts: a good implementation of a weak table should release memory as soon as possible to avoid memory leak; a good implementation of a cache should instead keep data as long as possible (until there is a good reason to release it, like resource exhaustion). In particular, data stored in a OCaml weak table will be released during the next collection cycle when it is no longer referenced by any strong reference; this is probably not what you expect from a cache! -- Alain