Re: [whatwg/dom] Owned weak event listener to prevent memory leak (using EventListenerOptions) (#243)

>I guess my point here is that removing listeners when they are added should be required always if the desire is to prevent memory leaks.

Actually, if the event target and the event listeners have same life time (or event listeners live longer), this is usually not required -- GC of event target usually means GC of event listeners. This is the case if all event listeners of a UI component are only added to component the and its children. But it can be problematic if the event target outlives its event listeners, e.g. event target is `document`, as described in my first post.

JS is a language with GC, but manual event listener management sometimes defeats the goal of GC. This proposal trys to make event listeners more GC-friendly.

>Additionally, passing an owner doesn't make it clear of what its actually being used for or why such a property needs to exist

I choose "owner“ to mean "Although this event listener logically belongs to Node x, it has to be added to one of x's ancestors. I want this event listener to die after Node x dies."

>I think your code should at the very minimum require an engineer to explicitly opt-in for this functionality

This functionality does require opt-in: if you omit the `owner` property, it is a traditional event listener.


---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/243#issuecomment-217827810

Received on Monday, 9 May 2016 10:18:59 UTC