Description
Multiple timers in HomeController are not properly disposed of, leading to memory leaks when the controller is closed.
Root Cause
In lib/app/modules/home/controllers/home_controller.dart, the onClose() method only cancels delayToSchedule. However, the controller also maintains a periodic _timer and a nullable _delayTimer. Since these are not cancelled, they continue to run in the background even after the user leaves the Home screen, consuming resources and potentially causing crashes.
Proposed Solution
Update onClose() to ensure all active timers are explicitly cancelled.
**Before:**
@override
void onClose() {
super.onClose();
if (delayToSchedule != null) {
delayToSchedule!.cancel();
}
}
**After.**
@override
void onClose() {
super.onClose();
_timer.cancel();
_delayTimer?.cancel();
delayToSchedule?.cancel();
}
Description
Multiple timers in
HomeControllerare not properly disposed of, leading to memory leaks when the controller is closed.Root Cause
In
lib/app/modules/home/controllers/home_controller.dart, theonClose()method only cancelsdelayToSchedule. However, the controller also maintains a periodic_timerand a nullable_delayTimer. Since these are not cancelled, they continue to run in the background even after the user leaves the Home screen, consuming resources and potentially causing crashes.Proposed Solution
Update
onClose()to ensure all active timers are explicitly cancelled.