An interesting thing happened while doing routine runs of Analyze in Xcode 4.2. I was able to track down and solve all of the memory issues that Analyze was reporting except for one, and for the life of my I couldn’t figure out what was wrong with this code:
if (![self.newBlahBlahBlah isEqualToString:anotherString]) { //... }
Then, i happened upon this thread on StackOverflow:
Objective-C – NSString copy property memory management – Stack Overflow
“Figured out what was wrong. I used the property name newFoo which made the compiler think I returned a new object. So note to self: understand cocoa naming conventions.”
…and then it clicked: the property “newBlahBlahBlah” was basically a violation of convention, and was tripping up Analyze, which assumed that the property returned an object with a +1 retain count. It didn’t, in reality.
So what was the solution?
Simply give the property a new name that doesn’t cause problems!
if (![self.awesomeNewblahBlahBlah isEqualToString:anotherString]) { //... }
Thankfully this issue, which had baffled me for weeks, was finally put to rest… and with a good lesson learned!