Weak event listener

Peter Michaux petermichaux at gmail.com
Mon Mar 25 19:51:03 PDT 2013

On Mon, Mar 25, 2013 at 2:55 AM, Marius Gundersen <gundersen at gmail.com> wrote:

> One thing which is impossible to make in JavaScript today is a weakly
> referenced event listener system. In such a system an event listener is not
> strongly referenced by the event system, so events are only dispatched to it
> as long as another object holds a reference to it.

Being able to make an observable subject that keeps a weak list of
observers would be very useful to ease memory management within an
application and avoid accidental memory leaks at the application
level. Sometimes the application programmer may forgot to remove a
observer from an observable subject, for example.

With regard to the MVC architecture, this could be the best addition
to the language to make application development easier. A view might
mistakenly not unsubscribe from its associate model when the view is
destroyed, for example. That or the view's destroy method is never
even called because the application programmer forgot to call it.


More information about the es-discuss mailing list