Usage for weak-maps

Bradley Meck bradley.meck at
Fri Oct 29 09:35:32 PDT 2010

I have used them in two ways in practical application.

A rather odd but quite interesting use case is short lived caches. Consider
a recursive static function such as the Fibonacci sequence. You could hold a
cache of the previous computations and allow them to be collected at the
GC's leisure.

Another use case is the ability to prevent memory leaks in situations where
you need to maintain a list of all the instances of an object to create
"class based" storage for Javascript Objects (generally through a


On Fri, Oct 29, 2010 at 10:33 AM, P T Withington <ptw at> wrote:

> On 2010-10-29, at 04:50, Peter van der Zee wrote:
> > What's the use case for weak maps? What would you do with it that
> currently
> > impossible and why is the workaround (if any) problematic enough to
> warrant
> > a weak map implementation?
> Another use case was mentioned in the "New topic regarding Proxies:
> intercession for ===" thread.  If you want to write a value type, the
> constructor needs to return the same object for identical parameters for ===
> to work, which means it needs a table of all the objects it has ever made,
> but it doesn't need (or want) to hang on to objects that are no longer in
> use.  [The alternative being discussed in the proxy thread is to be able to
> customize === to give the same illusion.]
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list