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

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

  • Follow-Ups:
    • Re: releasing NSKeyedUnarchiver causes crash
      • From: Markus Spoettl <email@hidden>
References: 
 >releasing NSKeyedUnarchiver causes crash (From: Markus Spoettl <email@hidden>)
 >releasing NSKeyedUnarchiver causes crash (From: Klaus Backert <email@hidden>)
 >Re: releasing NSKeyedUnarchiver causes crash (From: Markus Spoettl <email@hidden>)

  • Prev by Date: Re: Cocoa et al as HCI usability problem
  • Next by Date: Re: NSTreeController problems
  • Previous by thread: Re: releasing NSKeyedUnarchiver causes crash
  • Next by thread: Re: releasing NSKeyedUnarchiver causes crash
  • Index(es):
    • Date
    • Thread