Objective C 内存泄漏

发布于 2024-09-02 04:17:12 字数 505 浏览 5 评论 0原文

我正在为自己创建一个 Cocoa 应用程序,但发现了一个问题。我有两个 NSTextFields,它们作为 nextKeyViews 相互连接。当我使用内存泄漏检测工具运行这个应用程序并在这两个文本框之间切换一段时间,输入一些文本等时,我开始泄漏内存。它告诉我 AppKit 库是负责的,泄漏的对象是 NSCFStrings,负责的帧是 [NSEventcharactersIgnoringModifiers][NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] 。我知道这是一个非常简短且不完整的描述,但是有人知道可能是什么问题吗?

另外,我不使用 GC,因此我在控制器 deallocrelease我的实例变量。网点怎么样?由于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-09-09 04:17:12

门店怎么样?既然 IBOutlet 只是 Interface Builder 的一个标记,实际上没有任何意义,我是否也应该释放它们?

您的 IBOutlet 声明告诉您如何管理它...如果您将其声明为 retained,然后 @synthesize 它,则该过程加载笔尖将保留插座。因此您必须释放它。

Andiih 创造了助记符

NARC:“新分配保留副本”。如果你
没有做任何这些事情,你
不需要释放。

推论也是如此。如果您执行其中任何一项,您就有责任在适当的时间释放该对象。

What about the outlets? Since IBOutlet is just a mark for Interface Builder and doesn't actually mean anything, should I release them too?

Your declaration of the IBOutlet tells you how to manage it... If you declare it as retained and then @synthesize it, the process of loading the nib will retain the outlet. Therefore you must release it.

Andiih coined the mnemonic NARC

NARC: "New Alloc Retain Copy". If you
are not doing any of those things, you
don't need to release.

The corollary is also true.. if you do any of those, you are responsible for releasing the object at the appropriate time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文