• 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: Evan Schoenberg <email@hidden>
  • Date: Tue, 1 Mar 2005 02:45:16 -0600


On Mar 1, 2005, at 2:24 AM, Jiva DeVoe wrote:

You should instead do:

-(void)doSomething:(NSString *)aVar;
{
	localInstanceOfVar = [aVar retain];
}

And moreover, you want to do either:

-(void)doSomething:(NSString *)aVar;
{
	[localInstanceOfVar autorelease];
	localInstanceOfVar = [aVar retain];
}

or

-(void)doSomething:(NSString *)aVar;
{
	if(localInstanceOfVar != aVar){
		[localInstanceOfVar release];
		localInstanceOfVar = [aVar retain];
	}
}

because you want to release the old value before retaining the new one.

-Evan

_______________________________________________
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: Bob Ippolito <email@hidden>
References: 
 >Re: Memory management question (passing objects to method) (From: Jiva DeVoe <email@hidden>)

  • Prev by Date: Re: Memory management question (passing objects to method)
  • Next by Date: Re: 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