它将被释放。
原因是“Source”属性在Objective-C中是一个弱属性,这意味着那里的赋值不会在对象上调用retain,它只是保持对它的引用。
只有在 Objective-C 调用在传递的对象上保留时,才会发生阻止 GC 发生的强循环。
下面的例子展示了数据最终是如何发布的,你必须先向下钻取很多次,然后再向上钻取。
public class MyViewController : UITableViewController {
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.TableView.Source = new ViewSource(this);
}
public class ViewSource : UITableViewSource
{
public override int RowsInSection (UITableView tableview, int section)
{
return 100;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
return new UITableViewCell (UITableViewCellStyle.Default, "foo");
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
var n = AppDelegate.window.RootViewController as UINavigationController;
n.PushViewController (new MyViewController (), true);
GC.Collect ();
}
MyViewController _parentController;
public ViewSource(MyViewController parentController)
{
_parentController = parentController;
}
}
~MyViewController ()
{
Console.WriteLine ("Disposing");
}
}
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
public static UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
var myViewController = new MyViewController ();
window.RootViewController = new UINavigationController (myViewController);
window.MakeKeyAndVisible ();
return true;
}
}