Bug 47158 - System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Util.LruCache'
Summary: System.ObjectDisposedException: Cannot access a disposed object. Object name:...
Status: NEEDINFO
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 7.0 (C8)
Hardware: PC Windows
: High critical
Target Milestone: master
Assignee: Jonathan Pryor
URL:
: 46973 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-11-17 02:17 UTC by Gioan
Modified: 2017-09-06 13:53 UTC (History)
4 users (show)

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


Attachments

Description Gioan 2016-11-17 02:17:30 UTC
# Steps to reproduce
The old version:

Xamarin 4.1.2.18 (fcbe082)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android 6.1.2.21 (1cf254d)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS 9.8.2.22 (f37444a)
Visual Studio extension to enable development for Xamarin.iOS.

-> The app works fine.

------------------------------------------------------------------------------

Update to the new version:

Xamarin 4.2.0.719 (15694b9)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android 7.0.1.6 (5a02b03)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS 10.2.0.4 (b638977)
Visual Studio extension to enable developme_nt for Xamarin.iOS.

I'm using 'Android.Util.LruCache' to cache the bitmaps. When an Activity is destroyed I calls Android.Util.LruCache.EvictAll () method to release all bitmaps from LruCache. The problem occurs: 
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Util.LruCache'.

Sometimes, I also have the problem when I get a bitmap from 'Android.Util.LruCache'.

# Expected behavior
Android.Util.LruCache works as the old version

# Supplemental info (logs, images, videos)

11-15 10:25:30.655: I/MonoDroid(21130): UNHANDLED EXCEPTION:
11-15 10:25:30.665: I/MonoDroid(21130): System.ObjectDisposedException: Cannot access a disposed object.
11-15 10:25:30.665: I/MonoDroid(21130): Object name: 'Android.Util.LruCache'.
11-15 10:25:30.665: I/MonoDroid(21130): at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00030] in :0 
11-15 10:25:30.665: I/MonoDroid(21130): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00001] in :0 
11-15 10:25:30.665: I/MonoDroid(21130): at Android.Util.LruCache.EvictAll () [0x0000a] in <1ad43caae830460c9400510a1c85e4fd>:0

# Test environment (full version information)
Device: Samsung Galaxy Tab 4 (4.4.2)  

-------------------------------------------------------------------

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0447006-02725
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0447006-02725
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0447006-02725
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0447006-02725
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0447006-02725
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0447006-02725
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0447006-02725
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0447006-02725
Windows Phone SDK 8.0 - ENU

AnkhSVN - Subversion Support for Visual Studio   2.5.12582.28
AnkhSVN - Subversion Support for Visual Studio 2.5.12582.28 
 * Ankh.Package 2.5.12582.28
 * Subversion 1.8.11 via SharpSvn 1.8011.3473.77

SharpSvn is linked to: Apr 1.5.1, Apr-util 1.5.4, Cyrus Sasl 2.1.25, eXpat 2.1.0, OpenSSL 1.0.1l 15 Jan 2015, serf 1.3.8, SQLite 3.7.17, Subversion 1.8.11-SharpSvn-1.8.11, ZLib 1.2.8
SharpSvn is optionally linked to: Berkeley DB 4.4.20, SharpPlink 1.8011.3473.77

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Command Bus, Event Stream and Async Manager   Merq
Provides ICommandBus, IEventStream and IAsyncManager MEF services for loosely coupled Visual Studio extension components communication and integration.

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.12.0.817
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   4.2.0.719 (15694b9)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   7.0.1.6 (5a02b03)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   10.2.0.4 (b638977)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 Jonathan Pryor 2016-11-23 20:08:45 UTC
@Gloan: Xamarin.Android 7.0 ("Cycle 8") changed the default bridge from "old" to "tarjan". Please try using the "old" implementation:

https://developer.xamarin.com/guides/android/advanced_topics/garbage_collection/#GC_Bridge_Options

MONO_GC_PARAMS=bridge-implementation=old

If that fixes the issue, you found a GC bridge bug. (Yay?) If possible, please attach a test case so that our GC team can fix it.
Comment 2 Jonathan Pryor 2016-11-23 20:09:19 UTC
*** Bug 46973 has been marked as a duplicate of this bug. ***
Comment 3 Gioan 2016-12-06 17:06:55 UTC
@Jonathan Pryor: Sorry for late reply and thanks for your reply. I tried to use your suggestion

MONO_GC_PARAMS=bridge-implementation=old

It works, I don't have the problem any more. So I cannot attach my project here. I tried to write small app to reproduce the problem but I can not.

So I describe the layout of an activity in my app. It may help you to find a problem.

There are two activities: 
- The first activity contains a ListView. When the user presses on an item of the list the app will start the second activity.

- The second activity contains TabHost. There are three tabs in the TabHost. In per tab, I'm using Fragment to display the layout that contains RecylceView. I use RecycleView to display photos and use Android.Util.LruCache to cache photos. I selected the tabs four or five times(ex: select tab1->tab3->tab1->tab2->tab1,...) then I presses back button the problem occurs.

Important: when the Fragment is destroyed I will call Android.Util.LruCache.EvictAll() to release photos.

Detail layout here: https://postimg.org/image/5mgs4k8d5/

Hope to help you reproduce the problem.
Comment 4 Andi McClure 2017-01-25 19:27:30 UTC
Gioan— you say you cannot attach your "project"— would it be possible for you to share with us your *compiled app*? We do not need your source, but being able to run the app on our own phones and watch the crash happening would make a huge difference.
Comment 5 Ilnur 2017-05-29 10:57:57 UTC
Maybe related
https://bugzilla.xamarin.com/show_bug.cgi?id=56902

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