Alex Rivera | Logout

When to use -retainCount?

Asked 2011-01-08T21:07:14.560
113

I would like to know in what situation did you use -retainCount so far, and eventually the problems that can happen using it.

Thanks.

Edit
Report

2 Answers

15

Autoreleased objects are one case where checking -retainCount is uninformative and potentially misleading. The retain count tells you nothing about how many times -autorelease has been called on an object and therefore how many time it will be released when the current autorelease pool drains.

answered 2011-01-08T21:25:22.817
5

Take a look at the Apple documentation on NSObject, it pretty much covers your question: NSObject retainCount

In short, retainCount is probably useless to you unless you've implemented your own reference counting system (and I can almost guarantee you won't have).

In Apple's own words, retainCount is "typically of no value in debugging memory management issues".

answered 2011-01-08T21:11:03.227

Your Answer