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-31 (08:34)
From: vanicat@d...
Subject: Re: understanding weak
Alain Frisch <> writes:

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

It's true, but it could be interesting to have a cache pointer/cache
table provided with the garbage collector: it's the GC that know when
there is not enough memory left, and that it should free those cache
pointer to have some.

Rémi Vanicat