I'm trying to fix a huge memory leak that is caused somewhere in a method, that gets a NSData object from a CoreData datastore and unarchives that NSData back into a NSArray.
- (CustomObject *) getCustomObject
{
.... get myManagedObject from CoreData Store
CustomObject *customObject = nil;
if(myManagedObject)
{
customObject = [[[CustomObject alloc] init] autorelease];
NSData *arrayData = [myManagedObject valueForKey:@"resultArray"];
/* read and save resultArray */
NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:arrayData];
/* per definition decodeObjectForKey returns an autoreleased object */
/* Instruments (The Profiler) points out this line for the source */
/* of the memory leak. */
NSArray *myArray = [unArchiver decodeObjectForKey:@"rArray"];
/* myArray is a (nonatomic,retain) property in CustomObject */
[customObject setMyArray:myArray];
/* finishDecoding and release unarchiver */
[unArchiver finishDecoding];
[unArchiver release];
}
return customObject;
}
If i release myArray (what i should not do, since it is a autoreleased object) the memory leak disappears.
Does anyone know how you can solve this issue? The items in the NSArray of the CustomObject are NSDictionary objects.
thanks in advance
edit: - (CustomObject *) getCustomObject is called very often, so the impact of this leak is quite big.