Skip to content

Fix callback leaks and stale state during EventDisplay re-initialization#782

Merged
EdwardMoyse merged 1 commit into
HSF:mainfrom
remo-lab:fix/cleanup-callback-accumulation
Jan 24, 2026
Merged

Fix callback leaks and stale state during EventDisplay re-initialization#782
EdwardMoyse merged 1 commit into
HSF:mainfrom
remo-lab:fix/cleanup-callback-accumulation

Conversation

@remo-lab
Copy link
Copy Markdown
Contributor

Problem

During repeated initialization of EventDisplay, callbacks registered across multiple subsystems were not being consistently cleaned up. Specifically, callbacks registered by previous view instances remained referenced after EventDisplay was torn down, because cleanup paths did not fully clear stored listeners and stateful references.

In addition, StateManager continued to hold references to camera and menu objects from the previous initialization cycle, allowing callbacks tied to destroyed Angular components to remain reachable and executable. As a result, callbacks from older instances causing multiple handlers to fire for a single event.


Fix

This change ensures that all callbacks registered during an EventDisplay lifecycle are explicitly cleared during EventDisplay.cleanup(). It also resets internal references inside StateManager so that each re-initialization starts from a clean state. Guards were added to callback execution paths to prevent handlers from running after their owning components have been destroyed.


Impact

  • Prevents callback accumulation across EventDisplay re-initializations
  • Eliminates stale references retained by StateManager
  • Ensures callbacks from destroyed components cannot execute
  • Restone correct single-callback execution semantics

Clear accumulated callbacks in EventDisplay.cleanup() and add
StateManager.resetForViewTransition() to prevent memory leaks
and stale state when navigating between experiment views.

Signed-off-by: remo-lab <remopanda7@gmail.com>
@remo-lab
Copy link
Copy Markdown
Contributor Author

remo-lab commented Jan 20, 2026

Hi @EdwardMoyse @sponce
This PR fixes an issue where callbacks and state references weren’t being fully cleared during EventDisplay re-initialization, which could leave stale handlers and references around. The changes are small and focused on cleanup/reset paths. Happy to tweak anything if needed

@EdwardMoyse
Copy link
Copy Markdown
Member

Thank you very much!

@EdwardMoyse EdwardMoyse merged commit 81ebb81 into HSF:main Jan 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants