内存管理addSubview:

发布于 2024-11-28 19:21:10 字数 245 浏览 0 评论 0原文

我有一个 UIPickerView ,我将其分配为自动释放的对象,并在自身上使用 @property (nonatomic,retain) 来保留它。当我通过调用 [self.view addSubview:self.picker] 使其可见时,我应该随后调用 [self.picker release] 吗?我一直在这样做,但 Xcode 分析器显示“此时调用者不拥有的对象的引用计数递减不正确”。

谢谢!

I have a UIPickerView that I allocated as an autoreleased object and use a @property (nonatomic,retain) on self to hold on to it. When I make it visible by calling [self.view addSubview:self.picker], should I call [self.picker release] afterwards? I've been doing that but the Xcode analyzer says "Incorrect decrement of the reference count of an object that is not owned at this point by the caller".

Thanks!

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

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

发布评论

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

评论(2

九厘米的零° 2024-12-05 19:21:10

不。您已经自动释放了 UIPickerView。我假设您正在 dealloc 方法中释放属性引用。这就是你所要做的。在分配子视图后,视图负责子视图。

No. You've already autoreleased your UIPickerView. I'm assuming you're releasing the property reference in your dealloc method. That's all you have to do. The view is responsible for the subview after you've assigned it.

时光匆匆的小流年 2024-12-05 19:21:10

addSubView:保留子视图并在删除时释放它(removeFromSuperview)。这是隐式发生的。无需显式释放。

但是,如果出于任何原因您保留选择器,则必须释放它(您的问题中似乎并非如此)。

addSubView: retains the subview and releases it when removed (removeFromSuperview). This happens implicitly. No need to release explicitly.

how ever, if for any reason you retain picker, you will have to release it( which doesnt seem to be the case in your question).

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