Skip to content

Clarify ViewModel lifecycle & disposal in Compass sample #2788

@Turskyi

Description

@Turskyi

In the Compass sample, HomeViewModel (a ChangeNotifier) is created in the router and passed into HomeScreen, but it is never disposed.

While this is currently safe because HomeViewModel does not manage any disposable resources, this pattern may be confusing for readers who copy it into real apps where ViewModels often own streams, subscriptions, or controllers.

Would it make sense to:
• Add a short comment explaining that the ViewModel currently does not require disposal, and
• Clarify that lifecycle ownership would need to be addressed if disposable resources are introduced (e.g. via Provider/Riverpod or a StatefulWidget)?

This could help prevent accidental memory leaks when developers adapt the pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions