FFImageLoading icon indicating copy to clipboard operation
FFImageLoading copied to clipboard

Error when calling ClearCache

Open ahohns opened this issue 10 years ago • 9 comments

Am getting a crash occurring when calling:

FFImageLoading.Forms.CachedImage.ClearCache(FFImageLoading.Cache.CacheType.All);

This runs on the main thread after we dispose some pages (have tested it running before other pages are disposed as well just to be sure we aren't modifying the image cache at all).

Crash trace that occurs after a bunch of evictions:

An action scheduled for the main thread threw an exception: System.InvalidOperationException: Collection was modified after the enumerator was instantiated.
  at System.Collections.Generic.LinkedList`1+Enumerator[T].MoveNext () [0x00016] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/System/compmod/system/collections/generic/linkedlist.cs:519 
  at FFImageLoading.Cache.ReuseBitmapDrawableCache.Clear () [0x000a8] in <filename unknown>:0 
  at FFImageLoading.Cache.ImageCache.Clear () [0x00000] in <filename unknown>:0 
  at FFImageLoading.ImageService.InvalidateMemoryCache () [0x00018] in <filename unknown>:0 
  at FFImageLoading.Forms.Droid.CachedImageRenderer.ClearCache (CacheType cacheType) [0x0002d] in <filename unknown>:0 
  at FFImageLoading.Forms.CachedImage.ClearCache (CacheType cacheType) [0x00007] in <filename unknown>:0 
  at PROJECT.App.<.ctor>b__43 () [0x0005a] in App.cs:384 

ahohns avatar Jan 14 '16 04:01 ahohns

I'm pretty sure this was fixed a few days ago. Which version do you use?

molinch avatar Jan 14 '16 07:01 molinch

2.0.3 currently.

ahohns avatar Jan 14 '16 07:01 ahohns

Really weird I was sure it was fixed by https://github.com/molinch/FFImageLoading/commit/874b57e9f2395f34369285062e7c16bec52c9f7b

Which is part of 2.0.3

molinch avatar Jan 14 '16 08:01 molinch

I'll double check in the morning, I may have only updated to 2.0.3 in another branch.

ahohns avatar Jan 14 '16 09:01 ahohns

@molinch We could modify current implementation to use ConcurrentDictionary.

daniel-luberda avatar Jan 14 '16 11:01 daniel-luberda

As said in the commit message I don't think it's needed: all calls to the dictionaries are surrounded by locks. Furthermore the only cases where I found an issue, which wasn't a threading issue, are now having a .ToList()

As I said earlier, I don't think that @ahohns issue is still present in 2.0.3

molinch avatar Jan 14 '16 11:01 molinch

@molinch Ok then :)

daniel-luberda avatar Jan 14 '16 12:01 daniel-luberda

Yep my apologies, I was testing it on 2.0.2 10 minutes before merging in the 2.0.3 update. Works fine on 2.0.3 thanks.

ahohns avatar Jan 14 '16 23:01 ahohns

Thanks for the feedback!

molinch avatar Jan 15 '16 06:01 molinch