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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-04-2009, 09:11 AM   #1 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
Join Date: May 2009
Posts: 49
Default NSPopAutoreleasePool debug error

Hi,

I´m getting the folowing back tracing error:

Code:
#0  0x902be688 in objc_msgSend ()
#1  0x30506515 in NSPopAutoreleasePool ()
#2  0x309013d7 in _UIApplicationHandleEvent ()
#3  0x32054375 in PurpleEventCallback ()
#4  0x30245560 in CFRunLoopRunSpecific ()
#5  0x30244628 in CFRunLoopRunInMode ()
#6  0x308f904c in -[UIApplication _run] ()
#7  0x30901f2e in UIApplicationMain ()
The app crashes just after viewDidLoad has finished (my NSLog message at the very end of viewDidLoad is sent to the debugging window). viewWillAppear does not get called, but shouldAutoRotateToInterfaceOrientation does.

I've read elsewhere that this is a typical error if you manually release an object that you've already autoreleased, but I haven't autoreleased anything.

Anyone that's seen something similar?
oohmyygoood is offline   Reply With Quote
Old 07-04-2009, 09:37 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
Join Date: May 2009
Posts: 49
Default Solved

I stumbled upon the answer myself.

I had created a UIButton with this code:

Code:
UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
....;
....;
[b release]
What works is the following:

Code:
UIButton *b = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
....;
....;
[b release]
I'm not sure I understand why it needs to be like that, but there you go. :-)
oohmyygoood is offline   Reply With Quote
Old 07-04-2009, 10:56 AM   #3 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

buttonWithType returns an auto-released object. Since you didn't alloc that object, you should not be trying to release it. You can get rid of both the retain on that line, and the release later in your code.

joe
FlyingDiver is offline   Reply With Quote
Old 07-05-2009, 01:18 AM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
Join Date: May 2009
Posts: 49
Default Rule?

Interesting. It doesn't say in the Class Ref Library that buttonWithType returns an autorelease object.

Is this the case for other non-initWithXxxxxx methods that create and return objects as well? Such as [NSString stringWithString:] for instance?

I guess my question is if the rule is to only release objects that were created using an [.... alloc] init....] combo and all other methods return autorelease objects?
oohmyygoood is offline   Reply With Quote
Old 07-05-2009, 01:25 AM   #5 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

Quote:
Originally Posted by oohmyygoood View Post
Interesting. It doesn't say in the Class Ref Library that buttonWithType returns an autorelease object.

Is this the case for other non-initWithXxxxxx methods that create and return objects as well? Such as [NSString stringWithString:] for instance?

I guess my question is if the rule is to only release objects that were created using an [.... alloc] init....] combo and all other methods return autorelease objects?
Yes. Unless the method has init or a copy in the name, assume it returns an autoreleased objects, or maybe a singleton or shared instance. Either way, if you did not init/copy/retain then you should not release.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 07-05-2009, 04:26 AM   #6 (permalink)
Registered Member
 
Forsworn's Avatar
 
Join Date: Oct 2008
Location: Germany
Posts: 504
Default

Quote:
Originally Posted by smasher View Post
Yes. Unless the method has init or a copy in the name, assume it returns an autoreleased objects, or maybe a singleton or shared instance. Either way, if you did not init/copy/retain then you should not release.
'new' in the name indicates a non-autoreleased return object, too.
Forsworn is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 938
14 members and 924 guests
7twenty7, astalavista, betterlee, davidcoderlab, donlucacorleone, JuliaHarris, leticiatroutman, marWIN77, narutov2, nikhil, rocotilos, rodgo, Stokestack, watermelonvodka
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,479
Threads: 89,092
Posts: 380,125
Top Poster: BrianSlick (7,091)
Welcome to our newest member, JuliaHarris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0