Bug 16799 - UIAlertDialog Crash with dynamic delegate
Summary: UIAlertDialog Crash with dynamic delegate
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 7.1.0.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-12-14 03:12 UTC by David Screve
Modified: 2013-12-16 08:56 UTC (History)
2 users (show)

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

Problem example (8.88 KB, application/zip)
2013-12-14 03:12 UTC, David Screve

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:

Description David Screve 2013-12-14 03:12:04 UTC
Created attachment 5660 [details]
Problem example

If you use a dynamic Delegate with UIAlertDialog, application crash when user click on OK button.

Workaround : use delegate as member of the class.

See attached example : Clicking on "Click Me" and then "OK" work fine : Delegate is a member of the ViewController.

Then, click on "Crash me" and then "OK" : application crash because Delegate is dynamically created.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-12-16 08:56:04 UTC
This is sort of expected - you must make sure managed objects aren't freed before native code is finished with them.

In the crashing example the managed GC does not know that native code is still using the UIAlertView, and will thus the UIAlertViewDelegate (which only the UIAlertView references). And when you click the button, UIAlertView will try to call the "Clicked" method on the freed UIAlertViewDelegate.