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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Draw This
($0.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-26-2009, 07:01 PM   #2 (permalink)
BrianSlick
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,962
BrianSlick has a spectacular aura about
Default

There aren't too many cases where you HAVE to autorelease. In fact, due to the limited resources available on the iPhone, you want to avoid autoreleasing as much as possible.

Generally speaking, your variables should have a 3-step life.
  1. Creation. Ex: NSString *myString = [[NSString alloc] init];
  2. Use. Ex: [[cell textLabel] setText: myString];
  3. Release: Ex: [myString release], myString = nil;

As long as you do the release before you hit the last } in your method (or loop, depends on where you created it), you should be fine.

Other than that, I'd say that the rest of what you said is generally correct. You would need to post some specific examples of where you are crashing in order to get better help.



Edit:
Option 1 is correct (well, that may not be the best initialization example, since the string really doesn't have a value, but you get the idea). Option 2 is a leak.

IMO, do yourself a favor and avoid dot-syntax. Ex:

[self setStringIWant: string];
__________________
BriTer Ideas LLC - Code review, consulting, development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,014
Threads: 93,862
Posts: 401,918
Top Poster: BrianSlick (7,962)
Welcome to our newest member, Shimi574
Powered by vBadvanced CMPS v3.1.0

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