Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-04-2009, 03:33 PM   #5 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by MatuX View Post
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.
jsd is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,805
Threads: 89,205
Posts: 380,612
Top Poster: BrianSlick (7,129)
Welcome to our newest member, chloecoburn
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:14 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.