views:

126

answers:

1

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) 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?

+4  A: 

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.

MarkPowell
Thanks Mark. That's what I found in the official Apple documentation as well (see my edited question above). Did you have any bad experience regarding memory leaks created by Interface Builder itself. Meaning that something with the tool is wrong rather then with my code?
znq
I have never seen anything with the tool itself, no. Every memory leak I've ran into was due to my own mistake.
MarkPowell