• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSUnarchiver - Why does this leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 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.

  • Follow-Ups:
    • Re: NSUnarchiver - Why does this leak?
      • From: Daryn <email@hidden>
  • Prev by Date: Re: Is there a ready chart plotting view?
  • Next by Date: Re: Is there a ready chart plotting view?
  • Previous by thread: Re: non-preference use info saving
  • Next by thread: Re: NSUnarchiver - Why does this leak?
  • Index(es):
    • Date
    • Thread