Does these two snippets accomplish the same thing? Assuming I have three IBOutlet UIButtons in my interface file called buttonOne, buttonTwo, and buttonThree:
- (void)dealloc {
for(UIButton* idx in self.view.subviews)
[idx release], idx = nil;
[super dealloc];
}
and
- (void)dealloc {
[buttonOne release], buttonOne = nil;
[buttonTwo release], buttonTwo = nil;
[buttonThree release], buttonThree = nil;
[super dealloc];
}
Edit:
As ARC sometimes seems like a fix-all alternative to memory management in iOS, I prefer not to use it because a) I feel like I’m cheating and b) if I am not mistaken, it only works on iOS 5 devices.
Assuming you don’t have any other subviews, those two pieces of code do the same thing. But it’s not a thing you should do.
You should declare your outlets
weak(if using ARC) orassign(if not using ARC). Then you don’t have to release them indealloc. AUIViewretains its subviews and releases them when it is deallocated, so you don’t need to retain or release them. You just releaseself.view(or, if you’re a subclass ofUIViewController, you let[super dealloc]take care of releasingself.view).