문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top