Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory management - finding bugs earlier

I just spent a lot of time debugging a dumb mistake, (releasing a variable that I hadn't allocated) and wondered if there's a way to have XCode's Analyze warn me next time. The code was something like this:

@synthesize alfa, beta;
…
NSString *temp1 = [[NSString alloc] initWithString:@"AlfaText];
self.alfa = temp1;
[temp1 release];

NSString *temp2 = @"BetaText";
self.beta = temp2;
[temp2 release]

The last statement is (obviously?) a bug. Analyze seems to do a good job of reporting when you have too few [release]s, and having too many seems to be just as analyzable. Is there something that can be turned on that I'm missing?

like image 678
Andrew Avatar asked Dec 04 '25 13:12

Andrew


1 Answers

If the static analyzer didn't catch that, please file a bug. It really should have.

If you convert your projects to use ARC, both the lack of writing retain/release at all combined with the better analysis performed by the compiler will lead to many fewer memory management bugs.

like image 110
bbum Avatar answered Dec 07 '25 17:12

bbum