xamarin/Xamarin.Forms

Memory leak in ListView when deleting an item from the ItemsSource

Aperta

#3396 aperta il 25 lug 2018

 (17 commenti) (1 reazione) (0 assegnatari)C# (1926 fork)batch import
a/listviewe/3 :clock3:help wantedinactivep/Androidp/UWPp/iOS 🍎t/bug :bug:up-for-grabs

Metriche repository

Star
 (5644 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor