0
votes

I'm testing the code below, from the WROX book sample Mapping05 (find it here)

UIButton rightCallout = UIButton.FromType (UIButtonType.DetailDisclosure);
rightCallout.TouchDown += delegate {
//NSUrl url = new NSUrl ("http://wrox.com/");
//if (!UIApplication.SharedApplication.OpenUrl (url)) {
//  System.Console.WriteLine ("Sorry, can't open url");
//}
ShowAlert("iPad", "TouchDown");
};
pinView.RightCalloutAccessoryView = rightCallout;

But it fails: Debug info from gdb:

/tmp/mono-gdb-commands.n8GR64:1: Error in sourced command file: unable to debug self

================================================================= Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries

used by your application.

Any suggestions? I'm running the latest version on Monotouch, MonoDevelop and SDK 4.2

2

2 Answers

1
votes

MT 4.0 appears to be much more aggressive in it's GC. What is likely happening is that your rightCallout is locally scoped. When it goes out of scope, the GC purges it, so that when the delegate event fires there is no longer a reference to the button.

The easy fix for this is to scope your button at the class level, instead of inside your method.

See this: app crashes when handling navbar button event

0
votes

I know that problem. I think it's a probleme with the garbage Collection.

Because if you create List of UIButton in this Class and add ever rightCallout Button to it, it works without problemes.