• 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: NSCoding protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCoding protocol


  • Subject: Re: NSCoding protocol
  • From: Graham Cox <email@hidden>
  • Date: Sat, 4 Oct 2008 17:05:27 +1000


On 4 Oct 2008, at 9:29 am, email@hidden wrote:

But now I'm confused about how to de-allocate MyClass. Given this in its initialisation:

	S1 = @"a string";
	S2 = [[NSString alloc] init];
	S3 = [NSString string];

I would only release S2 in the dealloc method. But if the class has been unarchived, won't I leak memory with S1 and S3 when the class is released?


An approach that might help clarify this is to have accessor methods to set each string, rather than assign them directly in the initWithCoder method. Then you can write something like:

[self setFirstString:[coder decodeObjectForKey:@"blah"]];

then there's no special case when dearchiving compared with setting the string from any other place. And of course, the accesssor method would, as is the norm, retain the object.


Sending -retain to a constant literal string is fine, so you don't need to treat those as a special case either. So again:


[self setFirstString:@"Initial Value"];

is fine, even if the -setFirstString method retains the string, as it should.


hth,

Graham
_______________________________________________

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


References: 
 >NSCoding protocol (From: email@hidden)
 >Re: NSCoding protocol (From: "Stephen J. Butler" <email@hidden>)
 >Re: NSCoding protocol (From: email@hidden)

  • Prev by Date: Re: A way to use multiple colours with one NSBezierPath?
  • Next by Date: Re: Accessing Menu in Another Nib
  • Previous by thread: Re: NSCoding protocol
  • Next by thread: Re: NSCoding protocol
  • Index(es):
    • Date
    • Thread