This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
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
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows (show other bugs)
Version: 1.5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-06-26 13:46 UTC by Jimmy Garrido
Modified: 2017-03-28 18:50 UTC (History)
16 users (show)

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


Attachments
Repro Project (43.91 KB, application/zip)
2015-06-26 13:46 UTC, Jimmy Garrido
Details

Description Jimmy Garrido 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
Runtime:
	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: 8.10.2.35 (Business Edition)
Hash: 248c95e
Branch: master
Build date: 2015-06-20 10:58:19-0400

=== Xamarin.Android ===

Version: 5.1.4.16 (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: 2.0.2.35 (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
https://github.com/PureWeen/XamFormsListViewWeakProxy

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

http://1drv.ms/1GNbrUm

The issue happens a bit faster in WINRT
Comment 6 Jimmy Garrido 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 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
Hi, 

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 2017-03-16 01:14:18 UTC
https://github.com/xamarin/Xamarin.Forms/pull/802
Comment 14 Samantha Houts 2017-03-28 18:50:11 UTC
Should be fixed in 2.3.5-pre1. Thank you!

Note You need to log in before you can comment on or make changes to this bug.