Skip to content

Bug: Memory Leak in HomeController due to uncancelled Timers #884

@vibhutomer

Description

@vibhutomer

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();
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions