简体   繁体   中英

iOS Crash reports: Random objects receiving the wrong selector

I recently set up my app with HockeyApp to track crash reports. I've received many useful reports which I've used to fix bugs. However, I am getting a bunch of crash repots that give very strange explanations for what is causing the crash. See this one for example:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSFaultingMutableSet alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x1f2cd490'

Now, I do have a number of places in the app where I have alertView:didDismissWithButtonIndex: , but I never call it from an NSMutableSet . There are a number of similar kinds of crashes, where the selector is not at all affiliated with the object that is supposedly calling it. What would explain these kinds of crashes, and how can I go about fixing them?


EDIT:

First, as I explained in the comments to some of the answers, I'm using ARC. Also, here are some other examples, to give a sense of what is happening across the app:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString intValue]: unrecognized selector sent to instance 0x1ed29a90'


*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ myOwnInternalMethod]: unrecognized selector sent to instance 0x1edcf440'

This is a typical symptom of premature deallocation of an object. Check your memory management code and pay attention to reference counts (track when/how many times retain , copy , mutableCopy , release and autorelease are called).

这很可能是一个已被释放,被删除并且内存被另一个对象重用的对象的情况

are you using ARC? If not, most of this crashes occure when you release (or autorelease) an Object and not setting all references to this Object (for example delegates) to nil afterwards.

I choose a ScrollView as Example.

@interface MyExampleController : UIViewController <UIScrollViewDelegate>
@property(nonatomic, strong) UIScrollView *scrollView;

@end


@implementation MyExampleController

- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UITableView alloc] initWithFrame:CGRectZero];
        [_scrollView setDelegate:self];
    }
    return _scrollView;
}

- (void)dealloc
{
    // Normaly the ScrollView should die the same time the Controller does
    // but sometimes another object might hold a reference
    // so the delegate has to be set to nil to prevent the ScrollView to call an Object no longer exist
    [_scrollView setDelegate:nil];
}

@end

I do agree with H2CO3, Daij-Djan and Jonathan Cichon, that the reason probably is that a message is sent to a deallocated object.
One reason this can happen is if you have a thread without an autorelease pool set up, and you create an autorelease object. In this case it is not retained since no autorelease pool exists, and deallocated immediately after allocation. So, if you have multithreaded code, check if all threads have an @autoreleasepool{...} block that covers more or less the whole thread code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM