Bug 6264 - Selector invoked from objective-c on a managed object that has been GC'ed
Summary: Selector invoked from objective-c on a managed object that has been GC'ed
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2012-07-24 18:13 UTC by Jonas Sourlier
Modified: 2013-06-10 16:08 UTC (History)
7 users (show)

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


Attachments
Test project to reproduce the bug (13.73 KB, application/zip)
2012-07-24 18:13 UTC, Jonas Sourlier
Details


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:
Status:
RESOLVED FIXED

Description Jonas Sourlier 2012-07-24 18:13:26 UTC
Created attachment 2251 [details]
Test project to reproduce the bug

See the attachment, it's a simple MonoTouch project that reproduces the bug. Steps to reproduce:

1) Start the app
2) Press the button
3) Press the back button to navigate back
4) Repeat steps 2 and 3 until the crash occurs (usually in 5-15 seconds)

The first view controller creates a new instance of the ChildView controller every time the button is pressed (step 2). The old instance of the ChildView is nulled, so it can be garbage collected, since it is not anymore used by iOS. However, it seems that iOS keeps a reference to the old ChildView instances, because when a 'didReceiveMemoryWarning' is simulated in AppDelegate.cs, the app crashes since the managed ChildView instances have already been GC'ed.

See the following discussion on Stackoverflow: http://stackoverflow.com/questions/11609353/release-dispose-of-a-uiviewcontroller-in-monotouch
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-07-25 10:14:18 UTC
This actually looks like a GC (boehm) bug, it's not handling resurrecting weakrefs properly.

Sgen seems to work just fine.

Rodrigo, it looks like the gc clears out the target for resurrecting weakrefs before the dtor is called, so our intptr-nsobject mapping doesn't quite work as expected.
Comment 2 Sebastien Pouliot 2012-07-27 14:25:11 UTC
This is easy to duplicate (less than 30 secs) on 5.2.x but I could not duplicate it (after a few mins) on master. Boehm used in both cases.

5.2-series does not have the MonoTouch_Disposer IntPtr->NSObject fix.
Comment 3 Sebastien Pouliot 2012-07-27 16:16:23 UTC
nm comment #2, testing an (unrelated) mtouch fix using the same solution just crashed it
Comment 4 Jonas Sourlier 2012-08-14 03:42:37 UTC
Anybody knows if this is related to the critical update announced on August 13 on http://blog.xamarin.com ? The description there sounds like it could be related.
Comment 5 Sebastien Pouliot 2012-08-14 08:27:51 UTC
Jonas, No this is not related. The next MonoTouch release (5.3.6) will provide more information on this issue (i.e. a more complete exception message) to ease finding where those comes from.
Comment 6 Jonas Sourlier 2012-08-14 08:33:33 UTC
Thank you Sebastien!
Comment 7 Miguel de Icaza [MSFT] 2012-10-19 16:34:40 UTC
We have posted an update that could help in this situation, would you be so kind to download the binaries in this page (it contains a description of the changes) and report whether this solves the problem?

https://docs.google.com/a/xamarin.com/document/d/1o3FQ-2oxF-v85iAIAr6rsIGSgQ-eSUUteozJe7C5fWE/edit
Comment 8 Miguel de Icaza [MSFT] 2012-11-06 15:05:44 UTC
Opening the hidden comment, to expand testing.
Comment 10 Rodrigo Kumpera 2013-06-10 16:08:16 UTC
The fix has been back ported to 2.10. It's now a matter of landing it to a stable product.