How to check the retain count while debugging
Does anybody know how can I check the retain count of an object while in debug mode? I ha开发者_开发技巧ve tried to add an expression [objInstance retainCount]
but it did not work. I have also tried the print object PO [objInstance retainCount]
in the console but again it did not work.
I am guessing you are talking about getting the retainCount
in GDB
?
You can use the retainCount
method.
This is how I get in 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 isn't reliable due to things like autorelease
. You should rather read up on memory management and make sure that your retain
and release
calls match up. You can also run Build/Build and Analyze to get Xcode to help you find possible memory leaks, but again, these are only potential leaks. You'll need to check each one yourself to be sure.
精彩评论