English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
RE: understanding weak
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-10-30 (23:06)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] RE: understanding weak
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