开发者

Should I release self.view?

I have a question regarding to self.view in a UIViewController.

First, in my app, everything is created programmatically. And normally I create self.view in the loadView method:

self.view = [[UIView alloc]initWithFrame:SCREEN_FRAME]autorelease]; // SCREEN_FRAME is a constant

At this moment, the retain count of self.view is 1开发者_如何学Python.

So, my question is, do I have to release self.view when I'm done with the view controller? If so, where should I release it?

Thanks very much in advance :)


That is being done for you by the implementation of UIViewController, just make sure you call [super dealloc] in your dealloc method.


self.view is added autorelease pool and object will be release when pool is released. you don't need to release explicitly. If you add object to pool and release manually you will get exception double dealloc (since object is getting released twice)


Just for the reference of whoever might read this, the above answer is not exactly correct. self.view is called alloc, retain and autorelease, for the total retain count of 1. The retain call comes from the retain property and the dot syntax.

Therefore it DOES need to be released, but as willcodejavaforfood points out, the super implementation of dealloc does that.

Thanks

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜