Re: retain & release
Re: retain & release
- Subject: Re: retain & release
- From: Sherm Pendley <email@hidden>
- Date: Sat, 17 Sep 2005 21:20:03 -0400
On Sep 17, 2005, at 6:19 PM, Boyd Collier wrote:
In trying to follow the (supposedly) simple rules of using retain
and release
The rules *are* simple - you're complicating things by worrying about
internal details of code that isn't your problem.
---------------------------
#import "SPGDIController.h"
#import "MyDocument.h"
@implementation SPGDIController
- (IBAction)crunchNumbers:(id)sender {
unsigned count;
NSString *textViewContents = [[theTextView string] copy];
Here, you create textViewContents with -copy, so you need to balance
that with *one* -release.
NSScanner *theScanner = [NSScanner
scannerWithString:textViewContents];
The scanner may or may not retain the string here. If it does, it's
the scanner's job to release it when it's done with it. Either way it
has absolutely no effect on what you need to do with textViewContents.
[textViewContents release]; // count drops to 1
Again - the count is irrelevant. Your job is to balance *your* code,
so don't worry about what the scanner might have done internally. You
need to release textViewContents only once, because you created it
with -copy.
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
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