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
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.
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.
nm comment #2, testing an (unrelated) mtouch fix using the same solution just crashed it
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.
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.
Thank you Sebastien!
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?
Opening the hidden comment, to expand testing.
The fix has been back ported to 2.10. It's now a matter of landing it to a stable product.