I’m wondering if I am managing the memory of an Array correctly. Below I use this array with a tableView, so I want to keep it around for the life of the ViewController. Since I create it as a property I’m a little confused on the retain count and how to handle it since I’m alloc’ing it in the code. Below is how I currently have it coded.
in .h
@property (nonatomic, retain) NSMutableArray *mutableArray;
in .m
self.mutableArray = [NSMutableArray alloc] init];
//fill with object I'm going to be using throughout the life of the viewController
- (void) dealloc {
[mutableArray release];
[super dealloc];
}
Thank you!
You will leak your array if you’re doing it that way. because your property is set to retain,
self.mutableArray = [[NSMutableArray alloc] init];is the same asmutableArray = [[[NSMutableArray alloc] init] retain];.So change it to