Yet another memory management question
Yet another memory management question
- Subject: Yet another memory management question
- From: Bruce Truax <email@hidden>
- Date: Fri, 08 Sep 2006 11:32:12 -0400
- Thread-topic: Yet another memory management question
I have run into a memory management question that I do not understand. I
have the following method:
-(void)parseDataForVariable:(NSString *) variable
atSurface:(int)variableSurfaceNumber
withParameters:(NSString *)parameters
{
NSString *tempString;
NSString *selectorString;
SEL selectorForFunction;
tempString = [[NSString alloc] initWithString:[variable
capitalizedString]];
if ([tempString isEqualToString:@"Cv"]){
[tempString release];
tempString = [[NSString alloc] initWithString:@"Rd"];
}
selectorString = [[NSString alloc] initWithString:@"set"];
selectorString = [selectorString stringByAppendingString:tempString];
selectorString = [selectorString stringByAppendingString:@"Color:"];
selectorForFunction = NSSelectorFromString(selectorString);
//See if aSurface responds to the selector
if (!selectorForFunction == 0){
if ([aSurface respondsToSelector:selectorForFunction]){
//it responds so now send the message
[[surfaceArray objectAtIndex:variableSurfaceNumber]
performSelector:selectorForFunction
withObject:[NSColor redColor]];
}
}
[tempString release];
[selectorString autorelease];
}
As written this method works properly. If I change
[tempString release];
To
[tempString autorelease];
The program crashes when the popautoreleasepool function runs.
Also, if I try [selectorString release] the program will crash. I would
have thought that either release or autorelease would be valid for both of
these strings since I only use them locally.
--
____________________________________________________________
Bruce E. Truax email: email@hidden
Optical Engineering Consultant
Diffraction Limited Design LLC
388 Wedgewood Road voice: 860-276-0450
Southington, CT 06489 fax: 860-620-9026
http://www.dld-llc.com
_____________________________________________________________
_______________________________________________
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