开发者

Memory management addSubview:

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开发者_运维问答!


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: 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜