Does anyone know how I can check the number of times an object is held in debug mode? I tried to add the expression [objInstance retainCount] , but that did not work. I also tried the print object PO [objInstance retainCount] in the console, but again it did not work.
[objInstance retainCount]
PO [objInstance retainCount]
I assume you are talking about getting retainCount in GDB ?
retainCount
GDB
You can use the retainCount method.
This is how I enter my code.
(gdb) p (int)[product retainCount] $2 = 4
Hope this is what you are looking for.
You can print this with
NSLog(@"Retain count might be %d",[objInstance retainCount]);
However, this number is not reliable due to things like autorelease . You should rather read memory management and make sure your retain and release calls match. You can also run assembly / assembly and analysis to get Xcode to help you find possible memory leaks, but again, these are just potential leaks. You definitely need to check each one to make sure.
autorelease
retain
release