Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-10-2009, 06:34 PM   #1 (permalink)
RickMaddy
New Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
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
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 222
15 members and 207 guests
benoitr007, Breshi, codezy, dbonneville, iphonedave, irishkiwi, Jompe71, leeks, mizyeh, myPhone, n8r0n, pkouame, prathumca, Rashomon, smilespray
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,279
Threads: 39,072
Posts: 171,328
Top Poster: smasher (2,575)
Welcome to our newest member, yogen81
Powered by vBadvanced CMPS v3.1.0

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