• 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: Serge Meynard <email@hidden>
  • Date: Tue, 01 Mar 2005 02:56:26 -0500

It's essential to understand proper memory management if you're going to use Objective-C. The good news is, it's really quite simple.

Apple's relevant documentation is at http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ index.html. Look for the section called "Object Ownership".

Here are a few older links that might be a bit clearer than Apple's doc:
	http://www.stepwise.com/Articles/Technical/2001-03-11.01.html
	http://www.stepwise.com/Articles/Technical/HoldMe.html
	http://www.stepwise.com/Articles/Technical/MemoryManagement.html
	http://www.macdevcenter.com/lpt/a//mac/2001/07/27/cocoa.html

Serge


On Mar 1, 2005, at 01:09, email@hidden wrote:

I have a question about memory management and passing objects created in one method to another method. When/where do I release these objects? Example, if you will...

- (void)doSomething
{
   NSString* test = @"test";
   [self doSomethingElse:test];
}

- (void)doSomethingElse:(NSString*)test
{
   NSLog(@"%@", test);
}

Now, these are my questions, and I apologize if they're rather basic, I tried searching for an answer and didn't really find one. When "test" is passed to doSomethingElse, should I retain it in doSomethingElse, and then release it before the method ends? Or should I release it in doSomething after it is passed to doSomethingElse, retain it in doSomethingElse and release it when doSomethingElse ends?

I'm curious about this because I don't know, and I want to make sure I practice good memory management. Thanks for any and all help. Feel free to link to me past posts/articles that have already answered this.

James

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


This email sent to email@hidden


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

  • Prev by Date: NSURLDownload and server errors
  • Previous by thread: Memory management question (passing objects to method)
  • Next by thread: NSURLDownload and server errors
  • Index(es):
    • Date
    • Thread