Memory leak when returning object
Posted
by Yakattak
on Stack Overflow
See other posts from Stack Overflow
or by Yakattak
Published on 2010-03-12T17:36:48Z
Indexed on
2010/03/12
21:17 UTC
Read the original article
Hit count: 342
I have this memory leak that has been very stubborn for the past week or so. I have a class method I use in a class called "ArchiveManager" that will unarchive a specific .dat file for me, and return an array with it's contents. Here is the method:
+(NSMutableArray *)unarchiveCustomObject
{
NSMutableArray *array = [NSMutableArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithFile:/* Archive Path */]];
return array;
}
I understand I don't have ownership of it at this point, and I return it.
CustomObject *myObject = [[ArchiveManager unarchiveCustomObject] objectAtIndex:0];
Then, later when I unarchive it in a view controller to be used (I don't even create an array of it, nor do I make a pointer to it, I just reference it to get something out of the array returned by unarchiveCustomIbject (objectAtIndex). This is where Instruments is calling a memory leak, yet I don't see how this can leak! Any ideas?
Thanks in advance.
Edit: CustomObject initWithCoder added:
-(id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init])
{
self.string1 = [aDecoder decodeObjectForKey:kString1];
self.string2 = [aDecoder decodeObjectForKey:kString2];
self.string3 = [aDecoder decodeObjectForKey:kString3];
UIImage *picture = [[UIImage alloc] initWithData:[aDecoder decodeObjectForKey:kPicture]];
self.picture = picture;
self.array = [aDecoder decodeObjectForKey:kArray];
[picture release];
}
return self;
}
© Stack Overflow or respective owner