Reputation: 1807
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!
Upvotes: 0
Views: 155
Reputation: 833
iOS will do memory management by itself. Here is Apple Arc Documentation. There is also an excellent condensed information about memory management from Mikeash Friday Q&A blog
Upvotes: 0
Reputation: 4131
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 as mutableArray = [[[NSMutableArray alloc] init] retain];
.
So change it to
self.mutableArray = [NSMutableArray array];
Upvotes: 2