-(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;
}
views:
82answers:
1
+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
2010-08-24 23:20:13
+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
2010-08-24 23:21:57
thank you for a useful answer i greatly appreciate it.
Joe
2010-08-26 13:29:31