使用 IBOutlet/NIB 时的内存管理

发布于 2024-11-08 08:03:26 字数 381 浏览 0 评论 0原文

我的应用程序即将完成,我一直在使用 Instruments 对其进行分析。我正在检查各种对象的保留计数。

我一直小心地释放所有我调用过 alloc 的对象,并且这些对象似乎没有泄漏 - 所以这很酷。

但是,我有一个视图控制器,其中有一个 UIPickerView 。我通过将其拖到 IB 中的 NIB 上来进行设置,使用 IBOutlet 定义属性,合成它,然后将其全部连接起来。

每次我启动视图时,UIPickerViews 的数量似乎都会增加一个。我假设我不需要自己释放这种东西,因为我已经将它分配给了一个属性(使用非原子,保留)。

我的所有 UI 内容(按钮等)都发生这种情况,而不仅仅是选择器视图。我只是用它作为例子。

有人可以帮我吗?

谢谢!

My app is nearly finished and I have been Profiling it using Instruments. I'm checking out retain counts of various objects.

I have been careful to release any objects which I have called alloc on, and these don't seem to be leaking - so thats cool.

However, I have a view controller which has a UIPickerView in it. I set that up by dragging it onto my NIB in IB, defined the property using IBOutlet, synthesized it, and then hooked it all up.

Every time I launch the view, it seems the number of UIPickerViews increases by one. I was under the assumption that I do not need to release this kind of thing myself, as I had assigned it to a property (using nonatomic, retain).

This is happening to all my UI stuff - buttons etc, not just the picker view. I was just using that as an example.

Can anyone help me out here?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

淡紫姑娘! 2024-11-15 08:03:27

当视图加载时,从 NIB 创建的所有项目都会为您保留,并且您的 IBOutlet 指针将被初始化,指向那些保留的子视图对象。您需要在 viewDidUnload 中释放它们。你在这样做吗?

在 viewDidUnload 中,您应该释放从 NIB 创建的所有对象并将这些指针设置为 nil。您还应该在 dealloc 中释放这些相同的对象。 示例。

When the view is loaded all the items created from the NIB are retained for you and your IBOutlet pointers are initialized pointing to those retained subview objects. You need to release those in viewDidUnload. Are you doing that?

In viewDidUnload you should release all objects created from the NIB and set those pointer to nil. You should also release those same object in dealloc. Example here.

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