Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 - 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