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 02-06-2010, 09:04 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 36
Default UISegmented control dealloc crash

I got a crash log from my user. The "top" part of the log looks like this:

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000
Crashed Thread: 0

Thread 0 Crashed:
0 libobjc.A.dylib 0x000026f6 objc_msgSend + 18
1 UIKit 0x0011928c -[UISegmentedControl dealloc] + 12
2 CoreFoundation 0x00038f30 -[NSObject release] + 24
3 UIKit 0x00095c4c -[UIBarButtonItem dealloc] + 64
4 CoreFoundation 0x00038f30 -[NSObject release] + 24
5 UIKit 0x0008ec7a -[UINavigationItem dealloc] + 86
6 CoreFoundation 0x00038f30 -[NSObject release] + 24
7 UIKit 0x0009596c -[UIViewController dealloc] + 484
8 myApp 0x000041f6 -[myAppListViewController dealloc]

If I am reading this correctly, it has crashed trying to send a dealloc message to a segmented control (presumably the one I have on my navigation bar).

The relevant part of the segment control creation is:

NSString *strT = [self.dateformatUse stringFromDate:[NSDate date]];
NSString *strToday = [[[NSString alloc] initWithString:strT]autorelease];
NSArray *arSegments = [[NSArray alloc] initWithObjects:@"<",strToday,@">",nil];
UISegmentedControl *segctrlT = [[UISegmentedControl alloc] initWithItems:arSegments];
[arSegments release];
// set various segment control attributes
self.navigationItem.titleView = segctrlT;
self.segctrlTitle = segctrlT;
[segctrlT release];

in ViewDidUnload I have:

self.segctrlTitle = nil;

in dealloc for the view controller I have

[self.segctrlTitle release];

I am figuring either I shouldn't release (or rather should use autorelease) the components I use to build the segmented control in the creation part, or I shouldn't be setting it to nil in my ViewDidUnload routine. The crash is very elusive, so doing a "fix" and then testing it doesn't really work. I was hoping someone would see what I am doing wrong.
BrianMu is offline   Reply With Quote
Old 02-07-2010, 12:19 PM   #2 (permalink)
Will Work for Food!
 
itzdark's Avatar
 
Join Date: Apr 2009
Posts: 579
Send a message via AIM to itzdark Send a message via MSN to itzdark
Default

if you release it after you create it you dont need to release it again in the dealloc method.........
__________________

Check out my apps

Developers, check out study buddy. I use it everytime I code. It's great for those late night coding sessions.
Unofficial Ad Hoc Distribution Guide || Join my cooperative ad hoc testing group
iSoothe Promotional Video
Contact Me
itzdark is offline   Reply With Quote
Old 02-11-2011, 05:20 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 1
Default

Generally, whenever you release your ownership, you should also clear your reference.

So, two options, if you don't need any reference to your object after it has been created and added to the UI, you can just release and set the reference to nil. You don't need to do anything in the load's tearing down, or in the dealloc since you already released your ownership. In this case, you actually don't need an instance variable to reference it; a local variable will do. The UI still maintains ownership over the object (when you added it to as a subview) and will maintain it as long a the UI is shown.

On the other hand, in case you do need to hold a reference to the object throughout the UI's lifetime (for example to be able to update it), then the instance variable is correct. In this case, however, you should not release your ownership in the viewDidLoad and instead do that in the tearing down (and also set the reference to nil) and in the dealloc.
Since you are releasing your ownership and setting the reference to nil in the tearing down process, the dealloc one will do nothing; but it's still needed in case the tearing down process is skipped (allowed in iOS); in this case, the dealloc will release your ownership.
myok12 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
» Stats
Members: 158,480
Threads: 89,092
Posts: 380,125
Top Poster: BrianSlick (7,091)
Welcome to our newest member, premkumarmsc1
Powered by vBadvanced CMPS v3.1.0

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