I had some time tonight and decided to try to track down those 2 memory leaks that has been causing me grief for months now. I first did a find for all words 'alloc' and made sure they had releases, they did. I then questioned my code because I saw an example that you can write over a piece of code with the same name and it was not released and now you have a memory leak.
In the code snippet bellow I am wondering if I can legally do what I did with tempString. In my header I declared an NSString *tempString and I have been using that as a quick place holder. The string is not mutable so it can't change and yet I am changing it. Am I writing over the code causing a memory leak with this style of coding?
In the code snippet bellow I am wondering if I can legally do what I did with tempString. In my header I declared an NSString *tempString and I have been using that as a quick place holder. The string is not mutable so it can't change and yet I am changing it. Am I writing over the code causing a memory leak with this style of coding?
Code:
- (IBAction)endRoundButton:(id)sender { // ************************* Finish Turn
[COLOR="Red"]tempString = [hpTextField stringValue];[/COLOR]
if ([tempString isEqualTo:@"0"]) {
[errorTextField setTextColor:[NSColor redColor]];
[errorTextField setStringValue:@"NO NEW ENTRY"];
return;
}
[errorTextField setStringValue:@""];
dieRoll = [goodRollBonusTextField intValue];
[self convertButton:[hpTextField stringValue]];
critBonus = [critBonusTextField intValue];
runningCombatTotal = ((runningCombatTotal + dieRoll) + (hpStorage + critValue + critBonus)); // Adds up the total.
[COLOR="Red"]tempString = [critTextField stringValue];[/COLOR]
if ([tempString isEqualToString:@"-"]) {
;
}
else{
tempString = [NSString stringWithFormat:@"%d", hpStorage];
tempStringTwo = [critTextField stringValue];
tempString = [tempString stringByAppendingFormat: [tempStringTwo uppercaseString]];
...
..
.
}