tags:

views:

82

answers:

1
-(void)processGlyph:(int)glyphOne withGlyph:(int)glyphTwo
{
    answer = glyphOne + glyphTwo;
    NSString *tempText = [[NSString alloc] init];
    tempText = [NSString stringWithFormat:@"%i",answer];
    [self dispatchText:tempText];
    [tempText release];
}

-(void)checkReadyToProcess
{
    if (count >= 2) {
        [self processGlyph:firstGlyph withGlyph:secondGlyph];
    }
}

-(void)dispatchText:(NSString *) theText
{
    answerText.text = theText;
}
+7  A: 

Yes. It is here:

NSString *tempText = [[NSString alloc] init];//leaked
tempText = [NSString stringWithFormat:@"%i",answer];//creates new autoreleased object
...
[tempText release]; //causes an eventual crash

You are allocating an NSString, replacing the variable with an autoreleased NSString, and then releasing the autoreleased NSString. This will lead to a memory leak (from the original NSString) and a crash from over-releasing.

Instead, just do:

NSString *tempText = [NSString stringWithFormat:@"%i",answer];

You don't have to release it.

eman
+1 Gonna give you my vote because I answered this doubtfully and deleted my answer, while you wrote yours knowing what exactly is happening.
BoltClock
thank you for a useful answer i greatly appreciate it.
Joe