-
-
Save spouliot/72fd254a1d1223b0a5a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MonoTouch.UIKit; | |
using System.Linq; | |
namespace Xamarin.iOS.UIPageViewControllerMemory | |
{ | |
public class StartDialog : UIViewController | |
{ | |
private DataSource _dataSource; | |
private MasterDialog _master; | |
public StartDialog() | |
{ | |
Title = "WTF"; | |
} | |
UIButton button; | |
public override void ViewDidLoad() | |
{ | |
base.ViewDidLoad(); | |
button = new UIButton(UIButtonType.Custom); | |
button.SetTitle("Open", UIControlState.Normal); | |
button.BackgroundColor = UIColor.Green; | |
button.Frame = new System.Drawing.RectangleF(20, 150, 280, 44); | |
Add(button); | |
button.TouchDown += OpenMasterDialog; | |
Console.WriteLine (RetainCount); | |
} | |
UINavigationController nav; | |
private void OpenMasterDialog(object sender, EventArgs arguments) | |
{ | |
_dataSource = new DataSource(); | |
_master = new MasterDialog(); | |
_master.DataSource = _dataSource; | |
_master.OnDialogClosed += HandleOnDialogClosed; | |
_master.SetViewControllers( | |
new [] { _dataSource.GetViewController(1) }, | |
UIPageViewControllerNavigationDirection.Forward, | |
false, | |
null | |
); | |
nav = new UINavigationController (_master); | |
NavigationController.PresentViewController( | |
nav, | |
true, | |
null | |
); | |
} | |
private void HandleOnDialogClosed(object sender, EventArgs e) | |
{ | |
_dataSource.Dispose(); | |
_dataSource = null; | |
Console.WriteLine("Before: " + _master.ChildViewControllers.Length + | |
"/" + _master.ViewControllers.Length + ")"); | |
var childs = _master | |
.ChildViewControllers.ToList() | |
.Union(_master.ViewControllers); | |
foreach (UIViewController child in childs) | |
{ | |
child.RemoveFromParentViewController(); | |
child.Dispose(); | |
} | |
Console.WriteLine("After: " + _master.ChildViewControllers.Length + | |
"/" + _master.ViewControllers.Length + ")"); | |
_master.OnDialogClosed -= HandleOnDialogClosed; | |
_master.Dispose(); | |
_master = null; | |
// if you comment the next two lines HeatShot will report DetailDialog (after open/close) | |
nav.Dispose (); | |
nav = null; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment