Skip to content

[BUG] Memory leak without disposing 'WhenActivated' returned value  #2935

@parisq

Description

@parisq

Describe the bug
Hi, I found a memory leak by using WhenActivated in a view.
If we don't dispose the disposable returned by WhenActivated, it seems that the view and their elements are kept in memory.

With memory leak

public BookView()
{
  InitializeComponent();
  this.WhenActivated(d =>  {  ... });
}

Without

public BookView()
{
  InitializeComponent();
  IDisposable l_disp = Disposable.Empty;;
  this.WhenActivated(d =>
  {
    ...
    d(l_disp);
  });
}

Steps To Reproduce

  1. Run my simple application WPAFApplication.exe
  2. click a lot of time on "add" button to add objects in the list.
    2.1 Left list is the base case with a memory leak
    2.2 Right list is the 'fixed way' by disposing WhenActivated return
  3. then click on clear button
  4. make a snapshot with dot memory

Expected behaviour
We shouldn't have any view model retained by their views.

Screenshots
image
image

Environment

  • OS: W10
  • ReactiveUI Version: 16.2.6 and 16.2.1

Additional context
Have a good day :)

WpfApplication.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions