ios application crashed with "message send to deallocated instance" - ios

My app crashed and the code is the following:
else if(...)
{
CGDetailView *detailView = [[CGDetailView alloc] init];
ContactGroup *contactGroup = [[ContactGroup alloc] init];
[contactGroup setObjectStatus:NewObject];
[detailView setContactGroup:contactGroup];
[detailView newContactGroup:YES];
[contactGroup release];
UIBarButtonItem *temporaryItem=[[UIBarButtonItem alloc] init];
temporaryItem.title = NSLocalizedString(#"back", #"");
self.navigationItem.backBarButtonItem = temporaryItem;
[temporaryItem release];
[[self navigationController] pushViewController:detailView animated:YES];
[detailView release];
}
The error is "message sent to deallocated instance" and it regards the object of type
CGDetailView. I use the alloc-init-release pattern, and I don't really understand why the
app crashed. It usually works.
iOS 7.1 and device is iPhone5 if that helps.

Just try to get the point where your memory is released for this CGDetailView's object and you still calling a method on that object.
You can do it by enabling Zombie Object from edit scheme, it will tell you the point where your app is crashing.

Related

unable to find cause of EXC_BAD_ACCESS on a iOS7.1 app

I'm building a small demo app with MQTTKit and Estimote iOS SDK that ranges the beacons and sends the beacons proximity uuid, major and minor to a MQTT broker.
The sample works fine for a while, but sometimes it crashes and I get a EXC_BAD_ACCESS (code=2, address=0x27c8eff4)) on Thread 1 - Queue:com.apple.main-thread. In XCode, while debugging I can see the following when the exception throws:
CoreFoundation`CFRelease:
0x2fdc9f54: push {r4, r5, r6, r7, lr}
That is where the exception occurs, but I have no clue what that represents nor what it means.
Could anyone point out what is that I am not retaining or releasing to early, because from what I have read is something among the lines of objects being released to early and trying to access them after being released?
EDIT: As per the comment's suggestions, I have enabled NSZombies and breakpoints on exceptions and now I get more info:
Pulsr(21312,0x3cb4118c) malloc: *** error for object 0x16f27404: incorrect checksum for freed object - object was probably modified after being freed. *** set a breakpoint in malloc_error_break to debug
And the line where it stops is at [UIView animateWith ...];:
dispatch_async(dispatch_get_main_queue(), ^(void){
[UIView animateWithDuration:0.250
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
weakSelf.streamingCountLabel.layer.backgroundColor = streaming ? weakSelf.yellowColor.CGColor : weakSelf.redColor.CGColor;
}
completion:nil];
if (!streaming)
{
weakSelf.streamingCountLabel.text = #"0";
}
});
First thing that comes to my mind is this part:
- (instancetype)init
{
self = [super init];
return [self initWithUUID:ESTIMOTE_PROXIMITY_UUID identifier:#"Pulsr"];
}
- (instancetype)initWithUUID:(NSUUID *)uuid identifier:(NSString *)identifier
{
self = [super init];
if (self) {
_manager = [[ESTBeaconManager alloc] init];
_region = [[ESTBeaconRegion alloc] initWithProximityUUID:uuid identifier:identifier];
}
return self;
}
You are calling [super init] two times on one alloc. It might not be a problem but it's definitely wrong approach. In this case just remove [super init] from init method.

iOS Exception was thrown: unrecognized selector sent to instance

I have a problem. I am calling a method in another class. I call it before and it works perfect but I call back in another method near the end of the class and I have this error:
-(void)methodOne:(NSString*)myString
{
mySecondClasss *second = [[mySecondClasss init] autorelease];
[second doSomething:myString];
/*
more code
*/
}
-(void)methodTwo:(NSString*)myString
{
mySecondClasss *second = [[mySecondClasss init] autorelease];
[second doSomething:myString];
/*
more code
*/
}
In the second I'm getting this error:
Exception was thrown: -[mySecondClasss doSomething:]: unrecognized selector sent to instance. I don't understand why works once but not the second time. Any of you can give me some pointers of how can I fix this?
I'll really appreciate your help.
Since IOS 5 you have ARC (Automatic Reference Counting) which is automatically releasing the object correctly. Anyway you are not allocating the memory for the mySecondClasss class. Not sure why it even worked in the first method.
Instead of using
mySecondClasss *second = [[mySecondClasss init] autorelease];
Try using
mySecondClasss *second = [[mySecondClasss alloc] init];
Are you sure that you are sending a string to the function? The error implies that the function is not getting a string.
For example:
[self methodOne:#"Properly formatted string"];

Under ARC, keep getting EXC_BAD_ACCESS after using ARC, because of using Block?

Issue:
I keep getting EXC_BAD_ACCESS. And after I open NSZombieEnabled, I saw this [FeatureCommentListViewController respondsToSelector:]: message sent to deallocated instance 0x7c1dc30
Before I changed my project to ARC, there is no such error, but after I changed to ARC, this error appeared.
I declare a ViewController in a Block and push it into navigation Controller. Will this reason case it's lifetime shorter?
UIBlockButton is from this post
UIBlockButton *lbGood3 = [[UIBlockButton alloc] initWithFrame:CGRectMake(0, 0, First_Button_Width, [self getGoodRow2Height:productDetail]) ];
[lbGood3 handleControlEvent:UIControlEventTouchUpInside withBlock:^ {
NSLog(#"%#", Label.text);
ProductDetail *productDetail = [productDetailDict objectForKey:#"product"];
NSString *dp_id = [NSString stringWithFormat:#"%#-%#",productDetail.url_crc,productDetail.site_id];
FeatureCommentListViewController *cmtListController = [[FeatureCommentListViewController alloc] initWithNibName:#"FeatureCommentListViewController" bundle:nil];
cmtListController.title = Label.text;
cmtListController.isReviewed=isReviewed;
cmtListController.productDetail=productDetail;
cmtListController.dp_id=dp_id;
cmtListController.feature_name = #"&feature_good_id=2";
[self.navigationController pushViewController:cmtListController animated:YES];
}];
Should I declare the controller as a member of this viewController or just declare out of the block?
I solved this by alloc the FeatureCommentListViewController in the viewDidLoad function and use it in block.
1st. Im wondering why do you push a view controller in a block but not in the main thread? Isn't it important to give a quick response to the touch action?
2nd.[self.navigationController pushViewController:cmtListController animated:YES]; is in your block. Whenever you left the current navigationController what will the self.navigationController represent?
3rd. If you declare the viewController out of the block you can add __block in front of it as mentioned by Hermann Klecker.

iOS copyWithZone unrecognized selector only when using device

I'm working on an iPad app that launches an initial screen only when there is certain data in a sqlite DB, something like this:
if ((int)[MyStore sharedInstance].mode < 0)
{
self.connectionSettingsViewController = [[[ConnectionSettingsViewController alloc] initWithNibName:#"ConnectionSettingsModalViewController" bundle:nil] autorelease];
self.connectionSettingsViewController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
self.connectionSettingsViewController.delegate = self;
self.launchScreen = [[[UIView alloc] initWithFrame:CGRectMake(-256, 0, 1024, 768)] autorelease];
[self.launchScreen addSubview:self.connectionSettingsViewController.view];
[self.window addSubview:self.launchScreen];
}
That code is in the app delegate. The problem I'm facing is that this works fine in iOS Simulator, but when I try to run on iPad I get the following error:
[someViewController copyWithZone:] unrecognized selector sent to instance.
UIViewController doesn't implement the NSCopying protocol. Unless you've implemented NSCopying in your own UIViewController subclass, your view controller won't respond to -copyWithZone:.

iPhone - Button creates Action View, how to push class properties?

Hey guys, just had a question about UIAlertViews.
I have a button within a cell, and I wish to push an object's data into the UIAlertView body section. Right now I have this:
- (void)locationButton:(id)selector{
NSString *addressBody = [NSString stringWithFormat:#"%#", [[testList objectAtIndex:selectedCellIndexPath.row] address]];
UIAlertView *addressView = [[UIAlertView alloc] initWithTitle:nil
message:addressBody
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:#"Show on Map", nil];
[addressView show];
[addressView release];
}
Within the viewDidLoad, I initialized my Conference class like
testList = [[NSMutableArray alloc] init];
Conference *conf1 = [[Conference alloc] initWithConferenceId:110];
Conference *conf2 = [[Conference alloc] initWithConferenceId:130];
[testList addObject:conf1];
[testList addObject:conf2];
however when the button is pushed, the alert view does not display and it will eventually crash with
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Conference address]: unrecognized selector sent to instance 0x5e273a0'"
Any suggestions?
In your Conference class, there is no address method implemented.
This could just be a spelling mistake in the implementation. But it would be more helpful if you posted code in your Conference class.

Resources