Re: NSUnarchiver - Why does this leak?
Re: NSUnarchiver - Why does this leak?
- Subject: Re: NSUnarchiver - Why does this leak?
- From: Daryn <email@hidden>
- Date: Sun, 30 Mar 2003 23:05:33 -0600
If I recall correctly, the decoded objects are owned by NSUnarchiver.
Once the unarchiver object is destroyed, all the objects it decoded
will also be released. The unarchiver below is autoreleased, so
testing for leaks immediately after invoking leakTest will produce
misleading results. Try using an autorelease pool in leakTest and
check for leaks after releasing the pool. I suspect that it won't
appear to be leaking anymore.
On Sunday, March 30, 2003, at 08:24 PM, John Scalo wrote:
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
unarchiveObjectWithData: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.
Daryn
_______________________________________________
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.