Bug 31415 - ListView Does Not Update After GC When Collection Uses Weak References
Summary: ListView Does Not Update After GC When Collection Uses Weak References
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 1.5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-06-26 13:46 UTC by Jimmy [MSFT]
Modified: 2017-07-04 10:36 UTC (History)
17 users (show)

Is this bug a regression?: ---
Last known good build:

Repro Project (43.91 KB, application/zip)
2015-06-26 13:46 UTC, Jimmy [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jimmy [MSFT] 2015-06-26 13:46:34 UTC
Created attachment 11757 [details]
Repro Project

*** Overview ***
When a ListView is bound to a source that uses weak references for its event handlers, the ListView does not receive CollectionChanged events from the collection after GC occurs.

*** Steps to Reproduce ***
1. Run the attached repro project

*** Expected Results ***
The ListView should keep updating as more items are added to the collection.

*** Actual Results ***
When GC occurs (manually run after 5 items in the repro project) the ListView does not update with any new items added to the collection.

*** Environment Info ***
=== Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: 94ce5106-6a72-4691-b34e-cd5857b1db66
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Apple Developer Tools ===

Xcode 6.3.2 (7718)
Build 6D2105

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 248c95e
Branch: master
Build date: 2015-06-20 10:58:19-0400

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/jimmygarrido/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.3
Darwin Jimmys-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 2 Geoffrey Huntley 2015-06-28 19:10:52 UTC
Can we get the importance bumped up a notch higher than "Minor", this is a super annoying bug. See also https://github.com/reactiveui/ReactiveUI/issues/806#issuecomment-104662513
Comment 3 Eric Maupin 2015-07-01 12:32:30 UTC
Attempting to run this sample I get:

07-01 12:31:20.471 I/MonoDroid( 4508): UNHANDLED EXCEPTION:
07-01 12:31:20.477 I/MonoDroid( 4508): System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
07-01 12:31:20.477 I/MonoDroid( 4508): at System.ThrowHelper.ThrowInvalidOperationException (System.ExceptionResource) [0x00000] in /Users/builder/data/lanes/1196/6f9ba0bd/source/mono/external/referencesource/mscorlib/system/throwhelper.cs:94
07-01 12:31:20.477 I/MonoDroid( 4508): at System.Collections.Generic.List.Enumerator<XamFormsListViewWeakProxy.WeakHandler>.MoveNextRare () <0x00077>
07-01 12:31:20.477 I/MonoDroid( 4508): at System.Collections.Generic.List.Enumerator<XamFormsListViewWeakProxy.WeakHandler>.MoveNext () <0x00163>
07-01 12:31:20.477 I/MonoDroid( 4508): at XamFormsListViewWeakProxy.MyList.AddMonkey () [0x00070] in C:\Users\me\Downloads\XamFormsListViewWeakProxy\XamFormsListViewWeakProxy-master\XamFormsListViewWeakProxy\XamFormsListViewWeakProxy\App.cs:87
07-01 12:31:20.477 I/MonoDroid( 4508): at Java.Lang.Thread.RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/1196/6f9ba0bd/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
07-01 12:31:20.477 I/MonoDroid( 4508): at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/1196/6f9ba0bd/source/monodroid/src/Mono.Android/platforms/android-22/src/generated/Java.Lang.IRunnable.cs:71
07-01 12:31:20.477 I/MonoDroid( 4508): at (wrapper dynamic-method) System.Object.9e88fbd5-1093-497f-a059-c0a8920f971f (intptr,intptr) <IL 0x00011, 0x00043>
Comment 4 Shane 2015-10-13 12:50:42 UTC
It looks like the original sample was modified a little bit

Here is what I created originally to demonstrate the problem

a .ToList() was removed from the foreach loop there... 

So if you make line 87

 foreach (var handler in eventHandlers.ToList())

that should fix the exception
Comment 5 Shane 2015-10-29 15:56:48 UTC
I added WINRT to the sample ... Here's a link to the project in one drive


The issue happens a bit faster in WINRT
Comment 6 Jimmy [MSFT] 2015-10-30 18:56:09 UTC
Updated samples are provided in comment #4 and comment #5 hence marking this as NEW again.
Comment 7 Shane 2015-10-30 20:22:41 UTC
Hey Hey... Actually (AFAIK) this isn't related to the other issue I emailed you about... This bug is present on all platforms not just windows and has to do with the weak event handler getting GC'd

the sample for this one includes an android and WINRT version....  Whereas the other issue I'd emailed you about is a specific issue with WINRT and the LISTVIEW control when grouped
Comment 8 Kent 2016-02-07 23:57:37 UTC
Reported mid-2015, status "NEW". _sigh_
Comment 9 Jason Smith [MSFT] 2016-04-10 02:52:03 UTC
Sorry this apparently never got transferred to the right tracking system.
Comment 10 jason 2016-08-01 13:08:28 UTC
Any ETA on this? thanks.
Comment 11 Giusepe Casagrande 2016-09-15 22:37:28 UTC

Any plans on solving this?
I'm having this same issue with the last versions of Xamarin, Xamarin.Froms and ReactiveUI.

I created a sample based on my current project: https://github.com/GiusepeCasagrande/XamarinFormsBug31415Sample

If you run on Android all goes well, all the cells are rendered perfectly.
On iOS it won't show the cells unless I rotate the device and force to redraw.
Comment 12 thomas 2016-10-03 20:14:54 UTC
I also just encountered the same behaviour using ReactiveUI. The ListView did only get poplulated after the second time it was displayed.
Comment 13 Samantha Houts [MSFT] 2017-03-16 01:14:18 UTC
Comment 14 Samantha Houts [MSFT] 2017-03-28 18:50:11 UTC
Should be fixed in 2.3.5-pre1. Thank you!
Comment 16 Geoffrey Huntley 2017-07-04 10:36:47 UTC
Thank-you Samantha!
Comment 17 Geoffrey Huntley 2017-07-04 10:36:54 UTC
Thank-you Samantha!