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 03-10-2009, 07:34 PM   #1 (permalink)
RickMaddy
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,122
Default Memory Management 101

Since so many questions come up on this topic I thought I would give a quick summary on the basic rules of iPhone memory management. More specifically about when you should release an object.

Here's the simplest rule: If you directly call any of the following methods on an object then you must call release on the object:

alloc/init
retain
copy
mutableCopy

If you write a method that needs to return an object created with one of the above methods then your return value should look something like this:

Code:
return [result autorelease];
This allows your method to fulfill its obligation to release as required but the release won't happen until a little later so the code that calls this method has an opportunity to retain the result if required.
RickMaddy is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,677
Threads: 89,157
Posts: 380,396
Top Poster: BrianSlick (7,110)
Welcome to our newest member, Buster2000
Powered by vBadvanced CMPS v3.1.0

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