Apple says, that I need to have Outlets in my File's Owner for all my top level objects in a Nib file.
Apple说,我需要在我的文件所有者中为一个Nib文件中的所有*对象安装Outlets。
As much as I know, these objects are NOT the File's Owner itself (would make no sense, right?) and the First Responder.
据我所知,这些对象不是文件所有者本身(没有意义,对吧?)和第一响应者。
I am unsure about: The View object in the Nib, and any controller object in the nib. Do I need an outlet for those in File's Owner?
我不确定:Nib中的View对象,以及nib中的任何控制器对象。我是否需要文件所有者的插座?
This question is regarding memory management. They say:
这个问题与内存管理有关。他们说:
You should always keep a pointer to these objects somewhere because your application is responsible for releasing them wen it is through using them
您应该始终在某处保留指向这些对象的指针,因为您的应用程序负责通过使用它们来释放它们
So when the user closes the app, I would have a clunky memory leak if I'd miss those outlets?
因此,当用户关闭应用程序时,如果我错过了那些网点,我会有一个笨重的内存泄漏?
1 个解决方案
#1
That's correct. The File's Owner for a Nib file is the entry point into that nib. Since nothing outside your nib can refer to anything but the File's Owner, only the File's Owner can refer to other top-level items in the nib. If the File's Owner doesn't refer to them, then there is no way to release those objects when the nib is no longer needed, and they will hang around in memory.
那是对的。 Nib文件的文件所有者是该笔尖的入口点。由于笔尖外部没有任何东西可以引用除文件所有者之外的任何内容,因此只有文件所有者可以引用笔尖中的其他*项目。如果文件所有者没有引用它们,那么当不再需要笔尖时就无法释放这些对象,并且它们将在内存中徘徊。
The life cycle of a nib is something like this:
笔尖的生命周期是这样的:
- The nib is loaded and the File's Owner is associated with an object you specified.
- Memory is allocated for all the top-level objects in the nib.
- All the outlets are hooked up as specified in the nib.
- ... stuff happens ...
- The File's Owner object is sent a release message.
- The File's Owner releases all the objects hooked up to its outlets.
加载了nib,文件所有者与您指定的对象相关联。
为nib中的所有*对象分配内存。
所有出口都按照笔尖的规定连接起来。
......事情发生了......
File的Owner对象被发送一条释放消息。
文件所有者释放连接到其出口的所有对象。
As you can see, any object that was allocated in the second step will still be floating around in memory if it wasn't released in the final step.
如您所见,如果在最后一步中未释放,则在第二步中分配的任何对象仍将在内存中浮动。
#1
That's correct. The File's Owner for a Nib file is the entry point into that nib. Since nothing outside your nib can refer to anything but the File's Owner, only the File's Owner can refer to other top-level items in the nib. If the File's Owner doesn't refer to them, then there is no way to release those objects when the nib is no longer needed, and they will hang around in memory.
那是对的。 Nib文件的文件所有者是该笔尖的入口点。由于笔尖外部没有任何东西可以引用除文件所有者之外的任何内容,因此只有文件所有者可以引用笔尖中的其他*项目。如果文件所有者没有引用它们,那么当不再需要笔尖时就无法释放这些对象,并且它们将在内存中徘徊。
The life cycle of a nib is something like this:
笔尖的生命周期是这样的:
- The nib is loaded and the File's Owner is associated with an object you specified.
- Memory is allocated for all the top-level objects in the nib.
- All the outlets are hooked up as specified in the nib.
- ... stuff happens ...
- The File's Owner object is sent a release message.
- The File's Owner releases all the objects hooked up to its outlets.
加载了nib,文件所有者与您指定的对象相关联。
为nib中的所有*对象分配内存。
所有出口都按照笔尖的规定连接起来。
......事情发生了......
File的Owner对象被发送一条释放消息。
文件所有者释放连接到其出口的所有对象。
As you can see, any object that was allocated in the second step will still be floating around in memory if it wasn't released in the final step.
如您所见,如果在最后一步中未释放,则在第二步中分配的任何对象仍将在内存中浮动。