Till Schneidereit (2014-07-06T10:17:10.000Z)
domenic at domenicdenicola.com (2014-07-11T23:12:03.036Z)
There is [an ES7 proposal for weak references][1] that would satisfy your requirements. However, at least at Mozilla there is very strong opposition to this from people working on the memory management subsystems (i.e. the GC and CC). It's not clear to me that their arguments have been defeated and I'm not aware of any more recent discussions about this topic than those on Mozilla's platform development mailing list [2] [3]. While I think that weak references are an important feature, I don't think this particular use case is a good argument for them: in my personal experience working with and implementing systems like you describe, weak listeners were eventually deprecated and replaced by forced explicity unsubscription every time. If a view is destroyed, you really don't want it to receive any events anymore, regardless of the GC's timing. Now you could say that in the framework's event dispatching or handling mechanism you can detect this situation. If so, you can also just unsubscribe a strongly-held event listener at that point. [1]: http://wiki.ecmascript.org/doku.php?id=strawman:weakreferences [2]: https://groups.google.com/forum/#!topic/mozilla.dev.tech.js-engine.internals/V__5zqll3zc [3]: https://groups.google.com/forum/#!topic/mozilla.dev.tech.js-engine.internals/9LcqR9m5Mo4
domenic at domenicdenicola.com (2014-07-11T23:11:43.875Z)
There is an ES7 proposal for weak references[1] that would satisfy your requirements. However, at least at Mozilla there is very strong opposition to this from people working on the memory management subsystems (i.e. the GC and CC). It's not clear to me that their arguments have been defeated and I'm not aware of any more recent discussions about this topic than those on Mozilla's platform development mailing list[2][3]. While I think that weak references are an important feature, I don't think this particular use case is a good argument for them: in my personal experience working with and implementing systems like you describe, weak listeners were eventually deprecated and replaced by forced explicity unsubscription every time. If a view is destroyed, you really don't want it to receive any events anymore, regardless of the GC's timing. Now you could say that in the framework's event dispatching or handling mechanism you can detect this situation. If so, you can also just unsubscribe a strongly-held event listener at that point. [1]: http://wiki.ecmascript.org/doku.php?id=strawman:weakreferences [2]: https://groups.google.com/forum/#!topic/mozilla.dev.tech.js-engine.internals/V__5zqll3zc [3]: https://groups.google.com/forum/#!topic/mozilla.dev.tech.js-engine.internals/9LcqR9m5Mo4