Note the commented-out [printvolfirst release]; line below. If I un-comment it, the program crashes. I can’t figure out why. The printvolfirst variable is not used anywhere else except in the lines of code you see here. After it is assigned to printvol I’m done with it. So why not release it?
vol = vol / 1000000;
NSNumberFormatter * format = [[NSNumberFormatter alloc] init] ;
[format setPositiveFormat:@"#.#"];
NSString * printvolfirst = [[NSString alloc]init];
printvolfirst = [format stringFromNumber:[NSNumber numberWithFloat:vol]];
NSString * printvol = [[NSString alloc] initWithFormat: @"%@M", printvolfirst];
self.Pop.vol.text = printvol;
[printvol release];
//[printvolfirst release];
[format release];
stringFromNumber:autoreleases the returned object. If you release it again, it’s released after it has been deallocated.In fact, you don’t even need this code:
You can turn on ‘Run Static Analyser’ in the build settings to get warned about such things.