xamarin/Xamarin.Forms

Memory leak in ListView when deleting an item from the ItemsSource

Open

#3,396 opened on Jul 25, 2018

View on GitHub
 (17 comments) (1 reaction) (0 assignees)C# (1,926 forks)batch import
a/listviewe/3 :clock3:help wantedinactivep/Androidp/UWPp/iOS 🍎t/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

If you bind a ListView.ItemsSource to an ObservableCollection and then remove an item from that collection, then the associated renderers' Dispose method is not called. Only when the page is popped, then iOS disposes them, but Android and UWP do not. I did not check the other platforms.

Steps to Reproduce

  1. Create a ViewModel with an ObservableCollection
  2. Bind a ListView.ItemsSource to that collection
  3. Delete an item from the ObservableCollection

Expected Behavior

The renderers of all elements in the associated cell are disposed.

Actual Behavior

The Dispose method of those renderers is never called. I have to assume, that they are still in memory.

Basic Information

  • Version with issue: tested with XF 3.0 up to 3.2-pre1

Reproduction Link

In the attached repro project I created a CustomLabel with a CustomLabelRenderer just to see when which methods are called. These classes only log, when the important methods are called and with which arguments, but otherwise don't change behavior. Both the SplashPage and the MainPage show the log of those method calls. Repro_MemoryLeak.zip

Contributor guide