I would like to know if the following code is a good way to use the new @autoreleasepool
, should I use it this way or let the main autoreleasepool take care of the objects?
- (void) callingAutoReleasedObject, would probably be my viewDidAppear, or similar function.
Thanks!
- (UIBarButtonItem*)backButton {
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"CustomBackTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
return [backButton autorelease];
}
- (void) callingAutoReleasedObject {
@autoreleasepool {
[[self navigationItem] setBackBarButtonItem:[self backButton]];
}
}
From Apple's reference:
Personally I created several @autoreleasepool blocks in order to avoid HEAVY memory leaks, during background synchronization using Core Data, since the framework (which I love) creates an HUGE number of autoreleased objects, that MUST be drained to preserve available memory ;)