Quote:
Originally Posted by MatuX
If I do a refcount or retainCount for self.navigationItem.rightBarButtonItem it shows that it has 3 references!
Why? Should I care?
|
In general, you should not look at object retainCounts... They are often misleading. If you are using any framework classes, they will have retains all over your stuff (as you discovered). Don't worry about it. Remember, the goal isn't to make sure the retainCount is zero - the goal is to make sure all your retains & releases are
balanced. myfoo = [[foo alloc] init] does an implicit retain, so it must be balanced with a release or autorelease.
I used to use autorelease all the time because I didn't really understand what I was doing, but I'm trying to break the habit and use it only when absolutely necessary. You should prefer the method that Smasher mentioned. Alloc/init, then use the object or assign it somewhere else, then release. Clean and simple, immediately obvious that the retains & releases are balanced.
If you have any doubts about your code, I recommend investigating the
Clang Static Analyzer. It runs over your code and can identify problematic memory management areas for you in a way that the normal compiler and even the Leaks tool can't.