NSUnarchiver - Why does this leak?
NSUnarchiver - Why does this leak?
- Subject: NSUnarchiver - Why does this leak?
- From: John Scalo <email@hidden>
- Date: Sun, 30 Mar 2003 18:24:22 -0800
Recently leaks was showing some massive leakage in my code, and I've
narrowed it down to some unarchiving of a dictionary, and the data stored in
that dictionary. The dictionary is stored in a file, and the objects in the
dictionary are archived NSData objects that were archived from a simple
model object with a few NSStrings and an NSCalendarDate.
The reduced code that causes the leaks looks like:
- (void)leakTest
{
NSData *archivedData;
NSMutableDictionary *archivedDictionary;
NSMutableArray *archivedArray;
archivedDictionary = [NSUnarchiver
unarchiveObjectWithFile:path];
archivedData = [archivedDictionary objectForKey:@"Some_Key"];
archivedArray = [NSUnarchiver unarchiveObjectWith
Data:indexingData];
//this does not mitigate the leaking:
//[archivedArray removeAllObjects];
}
After exiting leakTest, the instance variables of every object in the
archivedArray are leaked, or so leaks tells me. Those objects have a simple
initWithCoder method:
- (id)initWithCoder:(NSCoder *)coder
{
[self setName:[coder decodeObject]];
[self setPath:[coder decodeObject]];
[self setModDate:[coder decodeObject]];
return self;
}
It's as if while archivedArray is autoreleased, the leaf-level objects
inside of it unarchived by NSUnarchiver are not. What's the correct way to
handle this?
Thanks
John
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.