Reputation: 7227
I am using Instrument leaks tools to check leaks in the code.
//MyClass.h
@property (nonatomic, retain) NSMutableArray *marrProperty;
//MyClass.m
NSSortDescriptor *createdTime = [[NSSortDescriptor alloc] initWithKey:@"createdTime" ascending:NO selector:@selector(compare:)];
NSArray *sortedArray = [self.anManagedObj.aRelationships sortedArrayUsingDescriptors:[NSArray arrayWithObject:createdTime]];
[createdTime release];
NSMutableArray *marr = [[NSMutableArray alloc] initWithArray:sortedArray];
self.marrProperty = marr;
[marr release];
After checking with the leaks tool in Instrument, I was told the leaks happened in the following code:
NSMutableArray *marr = [[NSMutableArray alloc] initWithArray:sortedArray];
self.marrProperty = marr;
I don't know why, because I just alloc and release well.
Upvotes: 0
Views: 189
Reputation: 1635
Have you implemented a custom setter for marrProperty? This could be a source of memory issues.
Additionally, you might prefer to use [[sortedArray mutableCopy] autorelease]
, instead of initWithArray:
followed by a release
. Simply for code clarity.
If you're not using ARC, make sure that you release marrProperty in -dealloc for that class.
Upvotes: 1
Reputation: 162722
Instruments is showing you were the leaked object was allocated, not where it was leaked.
You need to find the extra retain
. You can use Instruments to do that; the Allocations instrument can be configured to track retain/release events.
Upvotes: 4