fix: store idle watcher interval ID and listeners for proper cleanup#5789
fix: store idle watcher interval ID and listeners for proper cleanup#5789manvirsingh01 wants to merge 1 commit intosugarlabs:masterfrom
Conversation
|
✅ All Jest tests passed! This PR is ready to merge. |
|
@manvirsingh01 Pull from updated master. |
The idle watcher in _initIdleWatcher() creates a setInterval and attaches window event listeners, but neither the interval ID nor the handler reference was preserved. This prevented cleanup on reinitialisation and caused duplicate intervals to accumulate. Changes: - Store the interval ID in this._idleWatcherIntervalId - Store the event handler in this._resetIdleTimer - Store the event names in this._idleWatcherEvents - Add _destroyIdleWatcher() to clear interval and remove listeners - Guard _initIdleWatcher() to destroy any existing watcher first Fixes sugarlabs#5768
749ec81 to
1b01d5d
Compare
|
✅ All Jest tests passed! This PR is ready to merge. |
|
@manvirsingh01 Cleanup looks correct. One question: is _destroyIdleWatcher() also called during Activity teardown/unload? |
@manvirsingh01 I also had the same thought , if Activity instances can be torn down, should _destroyIdleWatcher() be invoked during the teardown lifecycle to ensure listeners don’t persist? |
|
Hey @vanshika2720 @parthdagia05, thanks for the review! Good catch — right now, It's not hooked into any teardown/unload flow yet, mainly because Music Blocks doesn't really have a formal "shutdown" step — the app just lives as a single page. So there's no natural place to call it on exit today. That said, I totally agree it's good practice to clean up on unload. I can add a beforeunload listener that calls |
Description
Fixes #5768
The idle watcher in
_initIdleWatcher()creates asetIntervaland attaches window event listeners, but neither the interval ID nor the handler reference was preserved. This prevented cleanup on reinitialisation and caused duplicate intervals to accumulate.Changes
this._idleWatcherIntervalIdthis._resetIdleTimerthis._idleWatcherEvents_destroyIdleWatcher()to clear interval and remove listeners_initIdleWatcher()to destroy any existing watcher firstTesting