Skip to content

[RelayCommand] implementation leaks subscribers #1017

Closed as not planned
Closed as not planned
@albyrock87

Description

@albyrock87

Describe the bug

The RelayCommand is leaking the command's subscriber when command's lifespan is bigger than the subscribers (i.e. singleton command with a Button subscriber within a pop-able page).

Regression

No response

Steps to reproduce

Check out this repository's branch: https://github.com/albyrock87/maui-shell-issues/tree/relay-command-leak

  • Start the iOS app
  • Tap on Open sub page
  • Press back
  • See the message saying that the button's reference is still alive

Now comment [RelayCommand] and uncomment the standard ICommand implementation above.
Repeat the steps and notice how the reference is gone.

https://github.com/albyrock87/maui-shell-issues/blob/relay-command-leak/BarPage.xaml.cs#L12-L31

Expected behavior

GC should be able to collect the command subscriber as it does with Command.

Screenshots

No response

IDE and version

Rider

IDE version

No response

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.3.2

Additional context

Image

Help us help you

No, just wanted to report this

Metadata

Metadata

Assignees

No one assigned

    Labels

    by designSome behavior that is intended and not an issuemvvm-toolkit 🧰Issues/PRs for the MVVM Toolkit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions