I think what I need is a map with primitive keys and non-null object values, 
entries of which can be removed & GC-ied if values are no longer referenced. If 
I understand Map / Set / WeakMap proposals non of them can be used to solve 
this issue or do I miss something ? 

Regards
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.com/
Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu)


On Friday, 2011-11-11 at 15:39 , Oliver Hunt wrote:

> A weak map can only remove an entry if both the key and value have died, in 
> many ES implementations a number of the primitives are not gc allocated and 
> so can never die, or are cached globally so have lifetime unrelated to any 
> given program.
> 
> The net effect of allowing such primitive values to be used as keys would be 
> to make the map "strong" and the associated values would not be able to be 
> collected.
> 
> --Oliver
> 
> On Nov 11, 2011, at 3:28 PM, Irakli Gozalishvili wrote:
> > I really need to know why WeakMaps don't accept primitives as keys, can 
> > anyone please reply ? 
> > 
> > Thanks!
> > --
> > Irakli Gozalishvili
> > Web: http://www.jeditoolkit.com/
> > Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu)
> > 
> > 
> > On Thursday, 2011-11-10 at 10:31 , Irakli Gozalishvili wrote:
> > 
> > > Hi, 
> > > 
> > > I was wondering what is a reason for disallowing non-object values as 
> > > keys in WeakMaps ?
> > > 
> > > Also, I think I have a pretty good use case for primitive keys:
> > > 
> > > Worker process sends messages to the (main) UI process, to initiate UI 
> > > notification. If user clicks that notification main process will worker 
> > > know that given notification was clicked:
> > > 
> > > (function(exports) {
> > > 
> > > let id = 0
> > > let listeners = WeakMap()
> > > 
> > > exports.notify = function notify({ onClick, message }) {
> > >   if (onClick) listeners.set(++id, onClick)
> > >   self.postMessage({ id: id, message: message })
> > > }
> > > 
> > > self.onmessage = function({ id }) {
> > >   let listener = listeners.get(id)
> > >   if (listener) listener()
> > > }
> > > 
> > > })(this)
> > > 
> > > Is my use case invalid ? At the moment I use custom map implementation 
> > > with a limited size, once map hits the limit oldest entries will be 
> > > removed. 
> > > 
> > > Regards
> > > --
> > > Irakli Gozalishvili
> > > Web: http://www.jeditoolkit.com/
> > > Address: 29 Rue Saint-Georges, 75009 Paris, France 
> > > (http://goo.gl/maps/3CHu)
> > > 
> > 
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss@mozilla.org (mailto:es-discuss@mozilla.org)
> > https://mail.mozilla.org/listinfo/es-discuss
> 

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to