question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using actions on elements triggered by events piles up listeners

See original GitHub issue

Hi there,

I’ve found that when elements are created and removed, for instance in an {{if}} statement, and include actions paired with native events, those events pile up (at least in chrome).

If this is happening with a lot of elements at once, for instance showing a list of 200 items, each with 3 inputs and 2 buttons, this can happen quickly, and cause memory problems.

You can also see the heap grow and never decrease on the example below of the “onClick” button.

Ember Twiddle: https://ember-twiddle.com/fb52fe588830908c7b12a0a396574434?fileTreeShown=false&numColumns=0

Screencast: https://monosnap.com/file/iWoH8QfcMdDPJTPtpaAq3vmTrt5t5o

In particular the result observed in the performance > memory > listener panel of chrome is quite different between these two: <button onClick={{action "click"}}>Button With "onClick" Action</button> and <button {{action "click"}}>Button w/ simple action</button> @locks suggested I mention @stefanpenner and @krisselden

Thanks! ember twiddle - listener test 2017-10-25 14-33-30 image 2017-10-25 14-35-44

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
stefanpennercommented, Jan 10, 2018

<button onclick={{action "doSomething"}}> is just the simplest, and will work with any DOM specified API. It is also takes the form as any other data binding.

<button anyProperty={{anyValue}}>

And under the hood it just does:

button.onclick = callback // no magic, just sets a property the same as a developer would.

<button {{action "doSomething" on="click"}}> is IMHO legacy, as it originates from before templates were aware of HTML syntax, and could do the above.

1reaction
krisseldencommented, Jan 10, 2018

@averydev the memory growth chart can climb simply because there is no GC pressure that does not mean there is a leak. I just did a comparison heap snapshot between a snapshot after toggling on/off 4 times and toggling on/off 100 times, there is no leak of the closure action or dom that was removed.

heapsnapshotcompare

Read more comments on GitHub >

github_iconTop Results From Across the Web

Action Listeners and Action Events | Ground-Up Java
Java uses many types of events. The simplest is the action event, which is used by buttons and several other components to indicate...
Read more >
Event Emitters and Event Targets - Node.js
The emit() method is used to raise specified events with the supplied arguments. All the registered event listeners are called synchronously. It ...
Read more >
JavaScript Event Listeners Ultimate Guide
When an event is triggered on an element it will bubble that event up the document tree to all the elements the element...
Read more >
How do I attach events to dynamic HTML elements with ...
I am adding a new answer to reflect changes in later jQuery releases. The .live() method is deprecated as of jQuery 1.7.
Read more >
The event loop - JavaScript - MDN Web Docs - Mozilla
The function setTimeout is called with 2 arguments: a message to add to the queue, and a time value (optional; defaults to 0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found