I'm using the push handler of Core Motion for accelerometer updates:
CMAccelerometerHandler accelerometerHandler = ^ (CMAccelerometerData *accelerometerData, NSError *error) {
// handle update
};
[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue]
withHandler:[[accelerometerHandler copy] autorelease]];
This code crashes. If I don't copy the block at all I get intermittent crashed on suspend/resume. If I remove the autorelease
it works fine, but I think this will produce a leak.
I also tried to assign the block to an ivar and release it after [motionManager stopAccelerometerUpdates]
. Crashes as well.
How comes? I always thought I've to balance any copy
/retain
with a release
/autorelease
?
See also: Copying blocks (ie: copying them to instance variables) in Objective-C