• 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
releasing NSKeyedUnarchiver causes crash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

releasing NSKeyedUnarchiver causes crash


  • Subject: releasing NSKeyedUnarchiver causes crash
  • From: Markus Spoettl <email@hidden>
  • Date: Sun, 18 May 2008 00:51:14 -0700

Hi all,

  once again I have a question I can't seem to figure out on my own.

I'm trying to implementing an NSDocument application, more specifically the load/store part of it. It actually works as expected, reading and writing my object graph to and from a file works fine. The problem is that when releasing the NSKeyedUnarchiver instance used to read the data, the application crashes - and I don't know why.

This is the exact code I'm using (tracks is an object that conforms to < NSCoding >)

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data];
[archiver setOutputFormat: NSPropertyListBinaryFormat_v1_0];
[archiver encodeObject:tracks forKey: @"myobject"];
[archiver finishEncoding];
[archiver release];
return [data autorelease];
}


- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error: (NSError **)outError
{
*outError = nil;
NSKeyedUnarchiver *archiver;
archiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];


    // release current data
    [tracks release];
    tracks = [archiver decodeObjectForKey: @"myobject"];
    [tracks retain];
    [archiver release]; // <--- crash here, no crash if commented out
    return YES;
}

The crash happens when [archiver release] is called. Since I own the object I have to release it and in my understanding it should no longer be necessary (the reading is finished at that point). Furthermore Leaks reports a leak if archiver is not released (which seem to be perfectly valid).

I've also tried [archiver autorelease] but that only delays the crash a little.

I don't understand the mistake I'm making, please help. Thanks!

Regards
Markus
--
__________________________________________
Markus Spoettl

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • releasing NSKeyedUnarchiver causes crash
      • From: Klaus Backert <email@hidden>
  • Prev by Date: Re: iPhone syncing
  • Next by Date: Re: Conditionally modifying NIBs?
  • Previous by thread: Re: iPhone syncing
  • Next by thread: releasing NSKeyedUnarchiver causes crash
  • Index(es):
    • Date
    • Thread