Array clone on DispatchEvent
See original GitHub issueI just noticed that in the DispatchEvent function from the EventDispatcher the listeners array is cloned on every call https://github.com/mrdoob/three.js/blob/dev/src/core/EventDispatcher.js#L71.
That doesn’t look like nice for the GC.
Is there any specific reason that I may be missing why this is working that way instead of just removing that line and iterate directly on listenerArray?
/cc @mrdoob
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to clone or re-dispatch DOM events? - Stack Overflow
I've just put together a module on npm called clone-event which essentially wraps the functionality described in this answer, which is what I ......
Read more >frame_support::dispatch::marker::Copy - Rust - Docs.rs
The implementation of Clone can provide any type-specific behavior necessary to duplicate values safely. For example, the implementation of Clone for String ...
Read more >Methods of Javascript Copy Array with Examples - eduCBA
1. Slice Method · array: The original array that you wish to copy to the other array. · newArray: This is the new...
Read more >ES6 Way to Clone an Array | SamanthaMing.com
When we need to copy an array, we often times used slice. But with ES6, you can also use the spread operator to...
Read more >JavaScript Array copyWithin() Method - W3Schools
Copy the first two array elements to the last two array elements: ... The copyWithin() method copies array elements to another position in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It could be possible for one of the callbacks to remove any of the other ones, right? Not just itself? So no matter what order you traverse the callbacks in you’ll wind up changing the behavior of the class in some cases if you don’t clone the array.
That makes sense yep, what about using
unshiftinstead ofpush? That will make the order correct even if iterating back-to-front https://jsfiddle.net/8nwqaept/I guess it could be nice to benchmark
unshiftperformance impact versusslice()+push😄