• 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: Memory management question (passing objects to method)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory management question (passing objects to method)


  • Subject: Re: Memory management question (passing objects to method)
  • From: Tim Lucas <email@hidden>
  • Date: Thu, 3 Mar 2005 13:58:28 +1100

On 02/03/2005, at 4:46 PM, mmalcolm crawford wrote:
That said, this pattern is unusual, and you are encouraged to use standard accessor methods pervasively. Better than the above would be to simply invoke:

[object setBlah:nil];

And also just to add to the above, this is the pattern you should use in your dealloc methods (you all write delloc methods, right?!).


For example, if you have something like the following:

- (id)init
{
	if(self = [super init])
	{
		[self setName:@""];
	}
	return self;
}
- (void)setName:(NSString*)aString
{
	if(aString != name)
	{
		[name release];
		name = [aString retain];  // (or copy if you want)
	}
}

then your dealloc should look like:

- (void)dealloc
{
	[self setName:nil];
	[super dealloc];
}

- tim lucas

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Memory management question (passing objects to method)
      • From: Dietmar Planitzer <email@hidden>
References: 
 >Re: Re: Memory management question (passing objects to method) (From: Conor Dearden <email@hidden>)
 >Re: Re: Memory management question (passing objects to method) (From: Justin Spahr-Summers <email@hidden>)
 >Re: Memory management question (passing objects to method) (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: NSUserPath for path to user folder?
  • Next by Date: RE: Memory management question (passing objects to method)
  • Previous by thread: Re: Memory management question (passing objects to method)
  • Next by thread: Re: Memory management question (passing objects to method)
  • Index(es):
    • Date
    • Thread