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

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

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-01-2009, 11:55 AM   #8 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
jsd is on a distinguished road
Default

Quote:
I thought autorelease marked the item for garbage collection at the later time, and GC is not available on the iphone.
not quite. autorelease just marks an object for a release action "at some point in the future." the future point is typically the next time the run loop is entered, which is usually pretty quick. (i'm qualifying this heavily with words like "typically" and "usually" because you can do things to interfere with this, but most of the time you won't.)

garbage collection, the way most people think of it, is completely automatic and happens outside the control of the programmer. autorelease is under your control.

my advice would be to only use autorelease when you are returning an object that you alloced. eg:

Code:
- (someobject *)myMethodReturningObject {
    someobject *myobject = [[someobject alloc] init];
    [myobject doSomethingToSetItUp];
    [myobject autorelease];
    return myobject;
}
As you can see here, you've alloced the object, so it is your responsibility to provide a balancing release message. However, you want to return it to another method, so you can't just release it, or it would be lost before the other method got it. Autorelease is your friend in this case.

Quote:
I'm coming from programming ruby the last couple of years - life used to be so easy....
tell me about it - i was doing perl and php for the last 10 years. cocoa was quite a kick in the pants, took me about 6-8 weeks to get comfortable with it.
jsd is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,639
Threads: 94,102
Posts: 402,830
Top Poster: BrianSlick (7,990)
Welcome to our newest member, sCarlRodriguezj
Powered by vBadvanced CMPS v3.1.0

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