Re: releasing NSKeyedUnarchiver causes crash
Re: releasing NSKeyedUnarchiver causes crash
- Subject: Re: releasing NSKeyedUnarchiver causes crash
- From: Jonathan Dann <email@hidden>
- Date: Sun, 18 May 2008 21:53:21 +0100
On 18 May 2008, at 18:04, Markus Spoettl wrote:
On May 18, 2008, at 5:25 AM, Klaus Backert wrote:
- (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];
As tracks seems to be an ivar, it would likely be better practice to
handle your memory management in an accessor, this way you never have
to remember to write retain and release multiple times:
- (void)setTracks:(id)newTracks;
{
if(tracks == newTracks)
return;
[tracks release];
tracks = [newTracks retain];
}
you can the just call [self setTracks:newValue];
see here:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAccessorMethods.html
To avoid writing accessors altogether, use Obj-C 2.0 properties.
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_2.html#/
/apple_ref/doc/uid/TP30001163-CH17-SW13
Sorry if I've told you things you know already and there was another
perfectly valid reason for doing what you did.
Jon
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