Does A-Frame automatically remove global event listeners when an entity is removed from the scene?
0 reputation · 11 Aug 2025, 05:17 UTC
This question concerns an A-Frame component that attaches event listeners to window and document during its init handler to track pointer and resize events across the full page.
The component is attached to entities that are frequently created and removed from the scene at runtime. A-Frame documents the remove lifecycle hook as the cleanup mechanism, but it is unclear whether the framework automatically detaches listeners bound to global objects when an entity is removed, or whether the component author must implement remove and call removeEventListener manually.
If global listeners persist after removal, the entity and its component may remain reachable and prevent garbage collection. It is also unclear whether this behavior differs across A-Frame 1.x releases.
Does A-Frame automatically remove window and document event listeners when an entity is removed from the scene? If not, is implementing the remove lifecycle hook the only reliable way to detach global listeners and avoid retained component memory?