Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iOS视图控制器未被释放?_C#_Ios_Uiviewcontroller_Release_Didreceivememorywarning - Fatal编程技术网

C# iOS视图控制器未被释放?

C# iOS视图控制器未被释放?,c#,ios,uiviewcontroller,release,didreceivememorywarning,C#,Ios,Uiviewcontroller,Release,Didreceivememorywarning,(我使用的是c#/Xamarin,但怀疑问题是否与此相关。) 当我添加一个视图控制器然后删除它时,它的DidReceiveMemoryWarning仍然被调用(在模拟器和真实设备上),所以它不可能被释放。我把范围缩小到:- UIViewController vc=(UIViewController)this.Storyboard.InstantiateViewController(identifier); this.AddChildViewController(vc); vc.RemoveFro

(我使用的是c#/Xamarin,但怀疑问题是否与此相关。)

当我添加一个视图控制器然后删除它时,它的DidReceiveMemoryWarning仍然被调用(在模拟器和真实设备上),所以它不可能被释放。我把范围缩小到:-

UIViewController vc=(UIViewController)this.Storyboard.InstantiateViewController(identifier);
this.AddChildViewController(vc);
vc.RemoveFromParentViewController();
vc=null;
调用DidMoveToParentViewController和WillMoveToParentViewController(如文档中所述)也无济于事:

UIViewController vc=(UIViewController)this.Storyboard.InstantiateViewController(identifier);
this.AddChildViewController(vc);
vc.DidMoveToParentViewController(this);
vc.WillMoveToParentViewController(null);
vc.RemoveFromParentViewController();
vc=null;
然后模拟一个内存警告,调用vc DidReceiveMemoryWarning,即使没有对它的引用。当它作为子控制器删除并且没有对它的引用时,这怎么可能呢

(当我使用故事板中设置的segue转到UINavigationController中的详细视图时也会发生同样的情况,例如,在“返回”到根控制器后,详细控制器仍然会收到DidReceiveMemoryWarning消息

任何有助于理解这一点的帮助都将不胜感激

更新: 现在我遇到的问题是嵌入在UINavigationController中的简单UIViewController

我添加导航控制器:

this.nc=(UINavigationController)this.Storyboard.InstantiateViewController("NavigationController");
this.AddChildViewController(this.nc);
this.nc.DidMoveToParentViewController(this);
并在以后(加载后)删除:

这一切都很好(没有保留)。但是如果我在嵌入的ViewController的ViewDidLoad方法中添加这条简单的线,那么ViewController将被保留

Console.WriteLine("this.NavigationController={0}",this.NavigationController);
也就是说,只要访问“this.NavigationController”就可以保留VC

所以每次我运行它时,都会保留另一个ViewController

Console.WriteLine("this.NavigationController={0}",this.NavigationController);

有什么想法吗?

可能是视图控制器的初始化方法产生了一些副作用,导致它保持活动状态。常见的例子是,它创建了一个
NSTimer
对象,该对象保留了它的目标。查看从情节提要实例化视图控制器时调用的方法,看看是否有任何问题g保留它。

添加c#标记会有所帮助,因为它不同于Obj-c语法(即Obj-c中的“this.”是“self.”).嗯,我确实有一个VC带有System.Timers.Timer,在一个案例中,它确实修复了它-非常感谢!我不得不停止它,删除事件并将其设置为null,以最终使其发布。我还有另一个VC不会发布,并且没有计时器或我能看到的任何其他东西。还有其他好主意吗?有没有办法找出它保留的原因?很简单UIViewController作为根vc的UINavigationController。