Re: retain & release
Re: retain & release
- Subject: Re: retain & release
- From: Boyd Collier <email@hidden>
- Date: Sat, 17 Sep 2005 20:56:50 -0700
Thanks very much to Sherm Pendley & Pete Yanell for their prompt and
very helpful replies. I thought that must be what was going on, but
newbies like me have a way of trying to make coding more complicated
than it has to be.
Boyd
On Sep 17, 2005, at 6:20 PM, Sherm Pendley wrote:
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