0

I follow this answer to trace my app for EXC_BAD_ACCESS. Yes, I got a zombie object. When I'm trying to figure out which line of my code is wrong, I found that all of the Responsible Libraries are Foundation.

Like this

When I'm trying to do this:

When you double click on any retain/release, instruments will show you line of code where this was performed.

It always takes me to some code with assembly language.

[assembly language (maybe?)[3]

I don't know how to trace my bug like this...

Update according to the answer of Elike.

The bug did happened when I update the title of a button. I use a timer to update a button title per second. You can tap the button to start/stop it. And I use dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_auto_duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{}); to auto run the method for 300 times (the bug happens randomly during 300 times).

I call the Timer like this _startcounttimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(StartCountTimerMethod) userInfo:nil repeats:YES];

- (void)StartCountTimerMethod
{
    _startcountbtnsec++;
    NSString *secstring = [NSString stringWithFormat:@"%d", _startcountbtnsec];
    [_startbtn setTitle:secstring forState:UIControlStateNormal];
}

And tap on the button will call this method:

- (void)StartBtnClick:(UIButton *)btn
{
    switch (btn.tag) {
        case 0:
            btn.tag = 1;
            [_startbtn setTitle:@"0" forState:UIControlStateNormal];
            _startcountbtnsec = 0;
            [self StartCountTimerStart];
            NSLog(@"Start!");
            break;

        case 1:
            btn.tag = 0;
            [_startbtn setTitle:@"Start" forState:UIControlStateNormal];
            [self StartCountTimerStop];
            NSLog(@"Stop!");
            break;

        default:
            break;  
    }
}

I can't see any problem with updating button text... And the zombie object is "NSThread".Is there any chance that the bug is about button and thread?

Community
  • 1
  • 1
Chien
  • 23
  • 6
  • It's hard. Keep in mind that the crash itself is diagnostic; the actual mistake happened long before. So, yes, at the time the message is sent to the zombie, it isn't your code. But your code set up the situation, earlier. You need to try to work backwards. – matt Feb 10 '17 at 04:06
  • Well, I was in a similar situation and I can tell for sure, there is no issue with the foundation libraries. Try running the static analyzer https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/static_analyzer.html (this will not solve issue, will just be the first step) check for potential memory leaks – Shravya Boggarapu Feb 10 '17 at 06:41
  • I've run the static analyzer but there are no potential memory leaks... – Chien Feb 10 '17 at 07:08

1 Answers1

1

I find it sometimes easier to just enable zombies in the schemes's diagnostics: Break on EXC_BAD_ACCESS in XCode?

Looking at your first screenshot the zombie is pretty obvious, but I agree the actual output is too generic. I don't know what your app is about but I would look for something where you update a button text (based on a notification ?).

Community
  • 1
  • 1
Eike
  • 620
  • 4
  • 6
  • Yes, I use a timer to update a button title per second. You can tap the button to start/stop it. I've edit my question for _update a button text _ code. Maybe I should put them to main thread? – Chien Feb 10 '17 at 06:27
  • @Chien I'm not sure if this is your problem but you should ALWAYS update your UI on the main thread. – halileohalilei Feb 10 '17 at 06:34
  • Yeah. I just not sure. If I didn't updates UI on the main thread, it should crash every time I call the method. But it happens randomly. – Chien Feb 10 '17 at 07:05