• 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: Yet another memory management question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Yet another memory management question


  • Subject: Re: Yet another memory management question
  • From: Buddy Kurz <email@hidden>
  • Date: Fri, 8 Sep 2006 08:58:40 -0700

This line: selectorString = [selectorString stringByAppendingString:tempString];
is replacing a retained NSString with an autoreleased NSString
You are leaking the initial value for selectorString.
When you autorelease selectorString it is already autoreleased.


one option:
selectorString = [[NSString alloc] initWithFormat:@"set% @Color",tempString];



On Sep 8, 2006, at 8:32 AM, Bruce Truax wrote:

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

_______________________________________________ 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: 
 >Yet another memory management question (From: Bruce Truax <email@hidden>)

  • Prev by Date: Categories to help with organization
  • Next by Date: Re: Yet another memory management question
  • Previous by thread: Re: Yet another memory management question
  • Next by thread: Re: Yet another memory management question
  • Index(es):
    • Date
    • Thread