capturingBlock (, , , , ). @autoreleasepool, , :
@autoreleasepool {
void(^capturingBlock)() = ^{
id capturedStrongReference = dummy;
};
capturingBlock = nil;
dummy = nil;
}
, @autoreleasepool ( exp waitForExpectations...). , , , , . :
- (void)testExample {
XCTestExpectation *exp = [self expectationWithDescription:@"strong reference should be deallocated when its capturing block is released"];
@autoreleasepool {
Dummy *dummy = [Dummy new];
dummy.deallocCallback = ^{
[exp fulfill];
};
void(^capturingBlock)() = ^{
id capturedStrongReference = dummy;
};
capturingBlock = nil;
dummy = nil;
}
[self waitForExpectationsWithTimeout:2.0 handler:nil];
}