When an NSString object is passed in as an argument, should I always do retain and release:
-forExample:(NSString*)str{
[str retain];
//do something
[str release];
}
or not? Where and when should I use this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The reference count of that object isn’t going to change over the course of this method, so there is no reason to send it
retain. From Apple’s Memory Management essay (which you should definitely look over):You only need to retain an object when you need it to stick around past the current scope.
If you have retained an object, you then need to send it
releasewhen you no longer need it.