When a event gets dispatched on a nested child with bubbling set to true, does the Event object itself get cloned for every display object that the event hits while ‘bubbling’ across the display stack? For example, does the Event.ENTER_FRAME event object get cloned for every display object that’s on the scene?
On a broad level, I’m trying to determine when Event.clone() occurs and where it can be a performance issues with too many event objects slowing down garbage collection.
Thanks!
Simple answer, yes the event always gets cloned. See the documentation to confirm.My original answer was wrong. The event does not always get cloned. As @weltraumpirat pointed out, the documentation says this only happens when you manually redispatch the event. It’s impossible to know how many classes (if any) that Adobe has written do this, but it is possible that some do. Still my answer “always gets cloned” was wrong.
However, that doesn’t mean that events are not the issue with your performance. They only get cloned if you re-dispatch an existing event, but if not, they still get dispatched as a new instance, which is exactly what the clone method is doing anyway.
Finally, we can see in the Tamarin source code, specifically in globals.as, the implementation of the
dispatchEventmethod:As you can see, the cloning happens here based on whether certain event properties are populated. I have not yet found the code where the target property gets populated, but at any rate there you have it. The clone method is only called where an existing event is re-dispatched (at least from what we can see). I stand corrected. 🙂
As a side note, I think this is a major flaw in the flash player. Adobe should have made this a special case in the VM where internally, it’s just a pointer that get’s passed around instead of cloning every single time the event is needed somewhere, especially given that the base-design of the AVM2 is an event-driven system.