0
votes

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.

1
Would help to see which message, and a stack trace. I'd recommend switching to ARC. If you don't want to do that, what does the static analyser say? - gnasher729
Try to get the crash point by Adding Exception Breakpoint : - Vinod Singh
[CGDetailView respondsToSelector:]: message sent to deallocated instance 0x79d9bc20 - cateof
Total guess: Because you are not using ARC, a pointer to your detailView is still stored as a delegate somewhere, even though it is deallocated. Again, static trace would help. Switching to ARC would really help because if the bug is what I guess it would go away. - gnasher729
@ShantiK: He doesn't show us a stack trace. respondsToSelector is very often called for optional protocols, and delegates often use optional protocols, and delegates without ARC are often stored as "assign" properties, so they are not set to nil when the delegate is deallocated. That together indicates that detailView is used as a delegate somewhere and the delegate is not set to nil at the right time. - gnasher729

1 Answers

0
votes

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.