Skip to content

RefreshView can have a memory leak with a custom ICommand #16124

@jonathanpeppers

Description

@jonathanpeppers

Description

This problem can be illustrated with a test such as:

main...jonathanpeppers:RefreshViewLeak

If you create a custom ICommand on something like a singleton ViewModel, and use it on a RefreshView, the RefreshView will live forever.

I think this is lower priority, as the customer samples I've seen use Command or Command<T>:

public event EventHandler CanExecuteChanged
{
add { _weakEventManager.AddEventHandler(value); }
remove { _weakEventManager.RemoveEventHandler(value); }
}

And WeakEventManager sidesteps this problem.

If we fix this, it might be worth auditing all properties of type ICommand.

Steps to Reproduce

  1. Create a custom ICommand
  2. Use it on RefreshView
  3. RefreshView lives forever

Link to public reproduction project repository

main...jonathanpeppers:RefreshViewLeak

Version with bug

8.0.0-preview.5.8529

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)

Affected platform versions

All

Did you find any workaround?

Use Command.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions