Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilize event deduping with addEventListener
The initial leak found here #761 And then patched here 957656d Was never the "correct" fix. Yes the patch in 957656d cause us to no longer leak however we were still paying the cost of registering and unregistering for the same event over and over, as well as allocating a new bound scope each time (thus generating more garbage and thus eventually causing more time to be spent int GC) Instead I opted here to take advantage of addEventListener and its ability to automatically discard duplicate listeners. > If multiple identical EventListeners are registered on the same > EventTarget with the same parameters, the duplicate instances are > discarded. They do not cause the EventListener to be called twice, and > they do not need to be removed manually with the removeEventListener > method. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Multiple_identical_event_listeners Because there is no outside pointers into this event, there is no need to remove the listener anymore, because once the node reference becomes unreachable the events will be automatically GCd for us. :)
- Loading branch information