开发者

iPhone: Interface Builder leaks memory?

开发者 https://www.devze.com 2022-12-28 06:14 出处:网络
I have been working on an iPhone project, where we created all the user interface programmatically in code. Now I\'m going to start a new iPhone project and thinking of using Interface Builder instead

I have been working on an iPhone project, where we created all the user interface programmatically in code. Now I'm going to start a new iPhone project and thinking of using Interface Builder instead, because it has been recommended to me as being a very useful tool, creating less headache than writing everything in code and in general much faster (regarding development time).

However, my team members have some concerns due to previous problems with using Interface Builder and resulting memory leaks. Therefor they suggest building everything in code again. I don't know where these concerns come from, but maybe someone with more experience than we have can give some insight on that topic.

Doing a simple Google search doesn't really provide any information proofing that there are any problems with memory leaks created by the Interface Builder itself.

By looking at the official documentation from Apple I only see these three things which I have to take care of:

@property (nonatomic, retain开发者_JAVA技巧) IBOutlet UIUserInterfaceElementClass *anOutlet;

"You should then either synthesize the corresponding accessor methods, or implement them according to the declaration, and (in iPhone OS) release the corresponding variable in dealloc."

- (void)viewDidUnload {
    self.anOutlet = nil;
    [super viewDidUnload];
}

Anything I missed?


When you assign an IBOutlet via Interface Builder, that object is retained by the controller by default (even without explicitly setting a property with retain). Therefore, you need to either release all outlets, or set a property with assign.

This is a gotcha that gets most people, and leads to the most common of memory leaks. Especially on views that are repeatedly show and removed.

0

精彩评论

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