My application will crash when i tried to clear the collection which have bound to a list view. When I commented out the Image, and two labels in dataTemplate section, it doesn't crashed.
The dataTemplate
<!-- Template for shared list due to ffimageloading package not work on iOS inside listview -->
<DataTemplate x:Key="androidItemTemplate">
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnDelete" CommandParameter="{Binding .}" Text="Delete" />
</ViewCell.ContextActions>
<StackLayout
Padding="12,10,12,10"
BackgroundColor="Transparent"
Orientation="Horizontal">
<ffimageloading:CachedImage
DownsampleToViewSize="true"
Aspect="AspectFit"
Source="{Binding FileThumbnail, Converter={StaticResource mimeTypeToImageConverter}}"
WidthRequest="60"
HeightRequest="60" >
</ffimageloading:CachedImage>
<StackLayout
Margin="12,0,0,0"
VerticalOptions="Center"
BackgroundColor="Transparent"
HorizontalOptions="FillAndExpand"
Orientation="Vertical">
<Label
VerticalOptions="Start"
HorizontalOptions="Start"
Text="{Binding DisplayName}"
TextColor="Black"
FontSize="Medium" />
<ProgressBar
VerticalOptions="Center"
HorizontalOptions="FillAndExpand"
Progress="{Binding Progress}"/>
<Label
VerticalOptions="End"
HorizontalOptions="Start"
Text="{Binding DisplayStatus}"
TextColor="Silver"
FontSize="Small" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
List View Code:
<ListView
x:Name="listFiles"
HasUnevenRows="true"
BackgroundColor="Transparent"
ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource itemTemplateSelector}"
ItemSelected="SharedList_ItemSelected"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
StackTrace
[mono-rt] Stacktrace:
[mono-rt]
[mono-rt] at <unknown> <0xffffffff>
[mono-rt] at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a (intptr,intptr&,intptr,intptr,intptr,Java.Interop.JniArgumentValue*) <0x0005b>
[mono-rt] at Java.Interop.JniEnvironment/InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference,Java.Interop.JniObjectReference,Java.Interop.JniMethodInfo,Java.Interop.JniArgumentValue*) [0x0008f] in /Users/builder/data/lanes/3511/501e63ce/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12079
[mono-rt] at Java.Interop.JniPeerMembers/JniInstanceMethods.InvokeNonvirtualVoidMethod (string,Java.Interop.IJavaPeerable,Java.Interop.JniArgumentValue*) [0x00022] in /Users/builder/data/lanes/3511/501e63ce/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:41
[mono-rt] at Android.Views.View.Measure (int,int) [0x0002a] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Android.Views.View.cs:13977
[mono-rt] at Xamarin.Forms.Platform.Android.ViewRenderer`2<TView_REF, TNativeView_REF>.GetDesiredSize (int,int) [0x00032] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\ViewRenderer.cs:71
[mono-rt] at Xamarin.Forms.Platform.Android.LabelRenderer.GetDesiredSize (int,int) [0x000f8] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\LabelRenderer.cs:60
[mono-rt] at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.IPlatform.GetNativeSize (Xamarin.Forms.VisualElement,double,double) [0x0008e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:183
[mono-rt] at Xamarin.Forms.VisualElement.OnSizeRequest (double,double) [0x0002d] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:624
[mono-rt] at Xamarin.Forms.VisualElement.OnMeasure (double,double) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:593
[mono-rt] at Xamarin.Forms.VisualElement.GetSizeRequest (double,double) [0x00053] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:469
[mono-rt] at Xamarin.Forms.VisualElement.Measure (double,double,Xamarin.Forms.MeasureFlags) [0x00054] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:527
[mono-rt] at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout/LayoutInformation,Xamarin.Forms.StackOrientation,double,double,double,double) [0x000a8] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\StackLayout.cs:150
[mono-rt] at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout/LayoutInformation,double,double,double,double,bool) [0x00058] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\StackLayout.cs:110
[mono-rt] at Xamarin.Forms.StackLayout.OnSizeRequest (double,double) [0x00019] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\StackLayout.cs:67
[mono-rt] at Xamarin.Forms.VisualElement.OnMeasure (double,double) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:593
[mono-rt] at Xamarin.Forms.VisualElement.GetSizeRequest (double,double) [0x00053] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:469
[mono-rt] at Xamarin.Forms.Layout.GetSizeRequest (double,double) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:110
[mono-rt] at Xamarin.Forms.VisualElement.Measure (double,double,Xamarin.Forms.MeasureFlags) [0x00054] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:527
[mono-rt] at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout/LayoutInformation,Xamarin.Forms.StackOrientation,double,double,double,double) [0x00236] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\StackLayout.cs:185
[mono-rt] at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout/LayoutInformation,double,double,double,double,bool) [0x00058] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\StackLayout.cs:110
[mono-rt] at Xamarin.Forms.StackLayout.LayoutChildren (double,double,double,double) [0x0005b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\StackLayout.cs:44
[mono-rt] at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x000c7] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:229
[mono-rt] at Xamarin.Forms.Layout.OnSizeAllocated (double,double) [0x0000f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:194
[mono-rt] at Xamarin.Forms.VisualElement.SizeAllocated (double,double) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:629
[mono-rt] at Xamarin.Forms.Layout/<>c.<OnChildMeasureInvalidated>b__39_0 () [0x00080] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:332
[mono-rt] at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/4009/9578cdcd/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
[mono-rt] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Java.Lang.IRunnable.cs:81
[mono-rt] at (wrapper dynamic-method) object.83dab5f1-80c5-4cdd-96fe-11ce4f52ba24 (intptr,intptr) [0x00011] in <8c304e4006094a46a7950338a3b3cb5d>:0
[mono-rt] at (wrapper native-to-managed) object.83dab5f1-80c5-4cdd-96fe-11ce4f52ba24 (intptr,intptr) [0x00021] in <8c304e4006094a46a7950338a3b3cb5d>:0
[mono-rt] /proc/self/maps:
If I removed all the label tag and leave the image, I will have this exception: Cannot access a disposed object.
Object name: 'FFImageLoading.Forms.Droid.CachedImageView'.