Bug 11283 - Xamarin.iOS 6.2.1: [UIPopoverController dealloc] reached while popover is still visible
Summary: Xamarin.iOS 6.2.1: [UIPopoverController dealloc] reached while popover is sti...
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-03-20 10:20 UTC by René Ruppert
Modified: 2013-05-15 09:13 UTC (History)
3 users (show)

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

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 INVALID

Description René Ruppert 2013-03-20 10:20:21 UTC
Referring to: http://forums.xamarin.com/discussion/comment/8435#Comment_8435

Running the sample code below on the Simulator (iPad 6.1) causes the exception below when pressing the "Test" button or latest when tapping outside the popover's area.
Making the popover static solves the issue.

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSGenericException Reason: -[UIPopoverController dealloc] reached while popover is still visible.
  at at (wrapper managed-to-native) MonoTouch.Foundation.NSObject:monotouch_release_managed_ref (intptr)
  at MonoTouch.Foundation.NSObject.ReleaseManagedRef () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:98
  at MonoTouch.Foundation.NSObject+NSObject_Disposer.Drain (MonoTouch.Foundation.NSObject ctx) [0x00062] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSObject2.cs:545
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at ReviewSelection.Application.Main (System.String[] args) [0x00000] in /Users/rene/Documents/Develop/ReviewSelection/ReviewSelection/Main.cs:17

=== Xamarin Studio ===

Version 4.0.2 (build 18)
Mono 2.10.12 (mono-2-10/c9b270d)
GTK 2.24.16
GTK# (2.12.0.0)
Xcode 4.6.1 (2067)
Build 4H512

=== Xamarin.iOS ===
Version: 6.2.1.201 (Enterprise Edition)


using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using BrainloopMobile.PSDPFKit;

namespace ReviewSelection
{
	// The UIApplicationDelegate for the application. This class is responsible for launching the 
	// User Interface of the application, as well as listening (and optionally responding) to 
	// application events from iOS.
	[Register ("AppDelegate")]
	public partial class AppDelegate : UIApplicationDelegate
	{
		// class-level declarations
		UIWindow window;

		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);
			window.MakeKeyAndVisible ();

			var popoverBtn = new UIBarButtonItem("Test", UIBarButtonItemStyle.Bordered, null);
			popoverBtn.Style = UIBarButtonItemStyle.Bordered;
			popoverBtn.Clicked += (sender, args) =>
			{
				var stack1 = new UIViewController();
				var stack2 = new UIViewController();
				var testNavController = new UINavigationController();
				testNavController.PushViewController(stack1, false);
				stack1.NavigationItem.RightBarButtonItem = new UIBarButtonItem("Push", UIBarButtonItemStyle.Bordered, (btnSender, btnArgs) => testNavController.PushViewController(stack2, true));

				var popController = new UIPopoverController(testNavController);
				popController.PresentFromBarButtonItem(popoverBtn, UIPopoverArrowDirection.Any, true);
			};

			var rootController = new UIViewController();
			rootController.NavigationItem.RightBarButtonItem = popoverBtn;

			var navController = new UINavigationController();
			navController.SetViewControllers(new UIViewController[] { rootController }, false);
			window.RootViewController = navController;

			return true;
		}

	}
}
Comment 1 Sebastien Pouliot 2013-05-14 16:24:20 UTC
It's not how it usually crash (it's actually better) but Adam (forums) was right, it's not a bug.

`popController` is a local variable. Once it goes out of scope (PresentFromBarButtonItem is not modal/blocking) then it becomes unreferenced and might be collected by the GC (which will eventually calls `dealloc`.
Comment 2 René Ruppert 2013-05-15 02:44:16 UTC
But what about the analogy to UIAlertView? I can use new UIAlertView().Show(); and it doesn't matter that it is going out of scope.
Comment 3 Sebastien Pouliot 2013-05-15 09:13:55 UTC
It look similar [1] but UIAlertView is very different internally (e.g. you can popup seveal of them at the same time, OTOH I'm sure there's many reasons I don't know, or only suspect, about). 

Anyway iOS keeps track of them, which means there's a native reference kept and that it knows when one is removed (so no leaks).

[1] enough that Xamarin.iOS does not do anything different between them.