开发者

What is the implication if I do not set a property = nil in viewDidUnload method?

I have defined a property in my viewcontroller as follows

@interface QuestionAnswerViewController : UIViewController 
{
    Question *question;
}

@property (nonatomic, retain) Question *question;

and I synthesized the property in my .m file

@synthesize question;

Will there be any issues if I don't set 'self.question = nil' in my viewDidUnload method?

- (void)viewDidUnload
{
    [开发者_如何学Pythonsuper viewDidUnload];
    //Any issues if I don't set this?
    self.question = nil
}

Reason why I am asking this is because the 'question property' is actually passed in from another view controller. I realised that in the case of low memory, my view controller's view will be automatically unloaded, so if I set self.question=nil, I will lose the information on the current page (self.question becomes nil). Just want to confirm the repercussions in not setting a synthesized property to nil and if there are any other ways to prevent this from happening.


You only release IBOutlets and those items that you can easily re-create on viewDidUnload.

If the view is unloaded, say automatically by a memory warning, any sub-components that are do not have their retains reduced will not be unload and less memory will be reclined that could be. This ultimately may cause your app to be terminated due to insufficient memory.

In iOS IBOutlets are retained so setting their property to nil releases them. Since the view that contains them is being unloaded these subviews have no reason to live, when the system reloads the view the subviews will also be reloaded at that time.


The implication is that those retained subViews of the mainView since they usually have a retain count of 2 for those declared as retain, one when it was set for the first time, and another one when it was added as a subView, when the superView is released the retain count will still be one.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜