Objective C 内存泄漏
我正在为自己创建一个 Cocoa 应用程序,但发现了一个问题。我有两个 NSTextFields,它们作为 nextKeyViews 相互连接。当我使用内存泄漏检测工具运行这个应用程序并在这两个文本框之间切换一段时间,输入一些文本等时,我开始泄漏内存。它告诉我 AppKit 库是负责的,泄漏的对象是 NSCFStrings,负责的帧是 [NSEventcharactersIgnoringModifiers]
和 [NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
。我知道这是一个非常简短且不完整的描述,但是有人知道可能是什么问题吗?
另外,我不使用 GC,因此我在控制器 dealloc
中release
我的实例变量。网点怎么样?由于IBOutlet
只是Interface Builder的一个标记,实际上没有任何意义,我是否也应该释放
它们?
I'm creating one Cocoa application for myself and I found a problem. I have two NSTextFields and they're connected to each other as nextKeyViews. When I run this app with memory leaks detection tool and tab through those 2 textboxes for a while, enter some text etc., I start to leak memory. It shows me that the AppKit library is responsible, the leaked objects are NSCFStrings and the responsible frames are [NSEvent charactersIgnoringModifiers]
and [NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
. I know this is quite a brief and incomplete description, but does anyone have any ideas what could be the problem?
Also, I don't use GC, so I release
my instance variables in the controllers dealloc
. What about the outlets? Since IBOutlet
is just a mark for Interface Builder and doesn't actually mean anything, should I release
them too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
IBOutlet
声明告诉您如何管理它...如果您将其声明为retained
,然后@synthesize
它,则该过程加载笔尖将保留
插座。因此您必须释放
它。Andiih 创造了助记符
推论也是如此。如果您执行其中任何一项,您就有责任在适当的时间释放该对象。
Your declaration of the
IBOutlet
tells you how to manage it... If you declare it asretained
and then@synthesize
it, the process of loading the nib willretain
the outlet. Therefore you mustrelease
it.Andiih coined the mnemonic NARC
The corollary is also true.. if you do any of those, you are responsible for releasing the object at the appropriate time.