简体   繁体   English

NSViewController未发布

[英]NSViewController not released

I have a question on the ownership of windows vs view controllers and when they're released. 我对Windows vs视图控制器的所有权及其发布时间有疑问。 I created a test project, and only added one line of code to the NSViewController: 我创建了一个测试项目,仅向NSViewController添加了一行代码:

deinit { print("ViewController Dismissed.") }

Why isn't this called when I close the window? 当我关闭窗户时为什么不叫它? I profiled it in Instruments and there aren't any memory leaks, but there is a reference to the ViewController still. 我在Instruments中对其进行了分析,并且没有任何内存泄漏,但是仍然有对ViewController的引用。

Also, I tried the "Release when closed" option on the NSWindow, still no dice. 此外,我尝试了NSWindow上的“关闭时释放”选项,但仍然没有问题。 Can anyone help with understanding this? 谁能帮助您理解这一点? Thanks!! 谢谢!!

Instruments的屏幕截图

I would have simply put this as a comment, but I don't have enough reputation: 我只是将其作为评论,但我没有足够的声誉:

Could there be a closure in your view controller that is maintaining a strong reference to your view controller or some object in your controller? 您的视图控制器中是否可能有一个闭包来维护对视图控制器或控制器中某些对象的强烈引用? That is one way a retain cycle can be created. 这是可以创建保留周期的一种方法。 If that was it, I would think it would show up in instruments, but it's just a thought. 如果是这样,我认为它会出现在乐器中,但这只是一个想法。

Also, is your view controller part of any kind of larger navigation system, such as a tab bar controller? 此外,您的视图控制器是否在任何较大的导航系统(例如标签栏控制器)中都属于一部分? That could be a factor. 那可能是一个因素。 I'm not sure. 我不确定。

As I know your running app always have the strong reference to a window instance, which in turn has the reference to a view controller. 据我所知,您正在运行的应用始终对窗口实例具有很强的引用,而窗口实例又具有对视图控制器的引用。 If you go to the Debug View Hierarchy after closing your window, you'll still see it there.If you remove storyboard entry point to that window in your storyboard, you wont have that window at all. 如果关闭窗口后转到“调试视图层次结构”,则仍会在其中看到。如果在情节提要中将情节提要入口点删除到该窗口,则根本没有该窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM