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 06-04-2009, 01:57 PM   #4 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,577
Default

Code:
	
[self.navigationItem setRightBarButtonItem:[[[UIBarButtonItem alloc]
	initWithTitle:@"Randomize"
	style:UIBarButtonItemStylePlain
	target:self
	action:@selector(randomizePositions)] autorelease]];
In this case, yes, I believe you should autorelease. You called alloc/init on the object, so you need to release it somewhere. The easiest way to do that is to call autorelease, so that it gets released at the end of the current event.

Don't worry about who else retained it, and why - that's their business.
Here's another, also correct, way to do what you're doing:

Code:
UIBarButtonItem *newItem = [[UIBarButtonItem alloc]
	initWithTitle:@"Randomize"
	style:UIBarButtonItemStylePlain
	target:self
	action:@selector(randomizePositions)];

[self.navigationItem setRightBarButtonItem: newItem];

[newItem release];
This doc was very helpful to me:
Very simple rules for memory management in Cocoa
__________________
smasher is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,335
Threads: 39,130
Posts: 171,565
Top Poster: smasher (2,577)
Welcome to our newest member, Mr.David
Powered by vBadvanced CMPS v3.1.0

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