 |
 |
|
 |
07-04-2009, 08:11 AM
|
#1 (permalink)
|
|
Member
iPhone Dev SDK Supporter
Join Date: May 2009
Posts: 43
|
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?
|
|
|
07-04-2009, 08:37 AM
|
#2 (permalink)
|
|
Member
iPhone Dev SDK Supporter
Join Date: May 2009
Posts: 43
|
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. :-)
|
|
|
07-04-2009, 09:56 AM
|
#3 (permalink)
|
|
Former NeXTStep Developer
Join Date: Mar 2009
Posts: 997
|
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
|
|
|
07-05-2009, 12:18 AM
|
#4 (permalink)
|
|
Member
iPhone Dev SDK Supporter
Join Date: May 2009
Posts: 43
|
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?
|
|
|
07-05-2009, 12:25 AM
|
#5 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,571
|
Quote:
Originally Posted by oohmyygoood
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.
__________________
|
|
|
07-05-2009, 03:26 AM
|
#6 (permalink)
|
|
Twitter: fabiankr
Join Date: Oct 2008
Location: Germany
Posts: 503
|
Quote:
Originally Posted by smasher
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.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 319 |
| 36 members and 283 guests |
| AgCode, ama269, Ath, bouche, chrisho_pro, Dathlon, develsolutions, dfletcher, Dorald, dre, falcon76, fwtag, Gamer211, gc2010, grgcombs, Grinarn, harkonian, hcarsten, headkaze, Hololon, hrom, ik8sqi, JonnyBGoode, kalygraphix, lanej, mauri, meeper, MiniRobinho, mitch2702, Mr Jack, naqviak, paul84, Pilly170, smasher, snowman88888, upperhouse |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,248
Threads: 39,028
Posts: 171,170
Top Poster: smasher (2,571)
|
| Welcome to our newest member, mitch2702 |
|