1

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";
    }
});
Roland
  • 9,321
  • 17
  • 79
  • 135
  • You can't find the line? NSZOmbies didn't help you? – Larme May 15 '14 at 12:55
  • Enable exception breakpoints, and include the call stack in your question. Also, enable Zombies as @Larme suggests. You'll be able to find instructions for all these steps pretty easily – jrturton May 15 '14 at 13:00
  • Try to run `Analyze` for your project, sometimes it is able to find obvious problems that you missed. – A-Live May 15 '14 at 13:08
  • @a-live I have done that and the only issue is a problem with one of the pods, some variable never being used. – Roland May 15 '14 at 13:37
  • @Larme, how do I find the line cause the issue using NSZombies? – Roland May 15 '14 at 13:37
  • @jrturton how do I enable exception breakpoints, I usually use AppCode, I don't use XCode that often? – Roland May 15 '14 at 13:38
  • @rolandjitsu: It should tell you what kind of object was released to soon, and what method was called for that object. It won't necessary tell you the line. And google it to know how to turn them on. – Larme May 15 '14 at 13:40
  • @larme, I have found the [instructions](http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode). I will run the app and will paste the results here as soon as I get it. Should I look in a specific place for the cause of the issue? – Roland May 15 '14 at 13:50
  • @rolandjitsu you enable exception breakpoints in app code in the debug pane, open the breakpoints window (search for "View Breakpoints" in the action search) and then tick where it says "Exception breakpoints" – jrturton May 15 '14 at 14:08
  • 1
    Try: http://stackoverflow.com/questions/19840671/malloc-error-for-object-0x208a7614-incorrect-checksum-for-freed-object-o – Larme May 15 '14 at 15:02
  • @larme, perhaps posting an answer with your comment suggestions might be a good idea, it is what actually helped to detect where the issue was. – Roland May 18 '14 at 00:52
  • @rolandjitsu: I just give suggestion to narrow down the issue. In fact, that's common search. If you look for how to debug a EXC_BAD_ACCESS, you'll find that Zombies, and other BreakPoints may help you to find a more accurate error message. But, I still don't know what was the real correction with your `UIViewAnimation`. You should be the one posting the solution, pointing exactly what was wrong in your code, what you changed to correct it, and maybe rename the question since EXC_BAD_ACCESS it to wide. – Larme May 18 '14 at 08:34

1 Answers1

1

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.

Konrad Szczęśniak
  • 1,960
  • 1
  • 14
  • 13
  • If I remove that it means if I call just `init` I will not be calling `[super init]` anymore. – Roland May 15 '14 at 13:40
  • 1
    No it doesn't - super init is called inside `initWithUUID:...`. This is your _designated initializer_: : https://developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/Initialization/Initialization.html – jrturton May 15 '14 at 14:07
  • You are right, my bad, I didn't pay attention to the code. Thanks for pointing it out :) – Roland May 15 '14 at 14:17