内存管理addSubview:
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不。您已经自动释放了 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.
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).