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

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

  • Follow-Ups:
    • Re: Yet another memory management question
      • From: Greg Titus <email@hidden>
    • Re: Yet another memory management question
      • From: Buddy Kurz <email@hidden>
    • Re: Yet another memory management question
      • From: j o a r <email@hidden>
  • Prev by Date: Re: Unable to parse xml
  • Next by Date: Re: Yet another memory management question
  • Previous by thread: How to Post arguments
  • Next by thread: Re: Yet another memory management question
  • Index(es):
    • Date
    • Thread