Skip to content

fix: add idle watcher interval cleanup and resource management#5770

Open
DhyaniKavya wants to merge 4 commits intosugarlabs:masterfrom
DhyaniKavya:fix/idle-watcher-clean
Open

fix: add idle watcher interval cleanup and resource management#5770
DhyaniKavya wants to merge 4 commits intosugarlabs:masterfrom
DhyaniKavya:fix/idle-watcher-clean

Conversation

@DhyaniKavya
Copy link
Contributor

issue : #5768

Problem:-
The idle watcher in js/activity.js creates a setInterval that runs every second to monitor inactivity and adjust the frame rate. The interval ID is not stored, and the activity reset event listeners are attached using a handler reference that cannot be removed.
As a result:
-the interval cannot be cleared if the activity is reinitialized
-duplicate intervals could accumulate in future lifecycle scenarios
-event listeners cannot be removed during teardown
-unnecessary resource usage may occur in long sessions or development reloads
-While this does not cause immediate user-visible errors, it represents incomplete lifecycle and resource management.

Solution:-
-This PR enables proper lifecycle cleanup while preserving all existing behavior:
-stores the idle watcher interval ID
-prevents duplicate intervals from being created
-stores the reset handler for listener removal
-adds a cleanup method to remove the interval and listeners
-does not change idle detection logic or behavior

Changes Made:-
-File modified:
->js/activity.js
->store interval ID for cleanup
->prevent duplicate interval creation
->store reset handler reference
->add cleanupIdleWatcher() method for lifecycle cleanup

Testing Performed:-
-Manual Verification
-Idle throttling activates after inactivity
-Frame rate restores on activity
-Playback and interaction behavior unchanged
-No console errors observed
-Automated Testing

Jest: ✅ all tests passed
Prettier: ✅ formatting verified
ESLint: ⚠️ pre-existing repository configuration warning (no new lint errors introduced)

Impact:-
-Improves resource and lifecycle management
-Prevents duplicate idle watcher intervals
-Enables safe cleanup for future modularization and testing
-Improves maintainability and long-session efficiency
-No breaking changes

Notes:-
This change is intentionally minimal and non-breaking. The cleanup method is opt-in and does not alter current behavior. It provides proper lifecycle handling for future use cases such as testing, development reloads, or modular integration.

Happy to adjust if maintainers prefer a different approach.

- Store interval ID in _idleWatcherIntervalId property
- Store reset handler in _resetIdleTimer for cleanup
- Prevent duplicate intervals with clearInterval check
- Add cleanupIdleWatcher() method to remove interval and event listeners
- No behavior changes to idle detection or FPS throttling
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@DhyaniKavya
Copy link
Contributor Author

@walterbender @vanshika2720 ES lint checks are not passing. I ran "npx prettier --write js/activity.js" but still checks are not passing . Can you suggest something?

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@DhyaniKavya
Copy link
Contributor Author

DhyaniKavya commented Feb 17, 2026

@walterbender @vanshika2720 sorry to ping you frequently . But now all the checks have been passed , there was some issue with the CI, i solved that now. Please review the changes if they are preferable. i am open to address and take notes of what you say. Thankyou

@vanshika2720
Copy link
Contributor

@DhyaniKavya I’ve reviewed the changes — the cleanup and interval handling look good overall.
Just one suggestion: it might be safer to invoke cleanupIdleWatcher() in the activity reset/stop path as well, to ensure full lifecycle cleanup.
Otherwise, the changes look good to me.

@DhyaniKavya
Copy link
Contributor Author

@vanshika2720 Thanks for reviewing and for the helpful suggestion
That makes sense , invoking cleanupIdleWatcher() during the activity reset/stop path would ensure complete lifecycle cleanup.
I’ll add that to the reset flow so the interval and listeners are cleared when the activity stops.

Appreciate the feedback!

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@DhyaniKavya
Copy link
Contributor Author

@omsuneri please review the changes if anything required , i am open to address them. Thankyou

@DhyaniKavya
Copy link
Contributor Author

@vanshika2720 please check if the changes are good for approval or need more changes

@vanshika2720
Copy link
Contributor

@DhyaniKavya I’ve reviewed the changes — they look good and properly handle the cleanup. Safe for approval from my side.

@DhyaniKavya
Copy link
Contributor Author

Thankyou @vanshika2720 for approving.
@walterbender Please review the changes done. Thankyou

@DhyaniKavya
Copy link
Contributor Author

@omsuneri This PR is ready for review, need approval from your side . Thankyou

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