Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 have 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.

like image 847
mrd3650 Avatar asked Sep 10 '11 19:09

mrd3650


2 Answers

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.

like image 131
Pranav Bhargava Avatar answered Oct 24 '22 13:10

Pranav Bhargava


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.

like image 42
PengOne Avatar answered Oct 24 '22 14:10

PengOne