mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-24 03:45:58 +08:00
[ASDisplayNode] Use Weak Proxy to Avoid Dangling CALayer.delegate (#2249)
* Add weak proxy between node and layer to avoid dangling layer problem * Add failing test case for dangling CALayer.delegate pointer issue * Add docs * Remove asynctransactioncontainer forwarding preprocessor macro * Improve comments * Remove asyncTransactionContainerStateDidChange callback
This commit is contained in:
@@ -1964,6 +1964,25 @@ static bool stringContainsPointer(NSString *description, id p) {
|
||||
XCTAssertNoThrow([nodeView removeFromSuperview]);
|
||||
}
|
||||
|
||||
// Running on main thread
|
||||
// Cause retain count of node to fall to zero synchronously on a background thread (pausing main thread)
|
||||
// ASDealloc2MainObject queues actual call to -dealloc to occur on the main thread
|
||||
// Continue execution on main, before the dealloc can run, to dealloc the host view
|
||||
// Node is in an invalid state (about to dealloc, not valid to retain) but accesses to sublayer delegates
|
||||
// causes attempted retain — unless weak variable works correctly
|
||||
- (void)testThatLayerDelegateDoesntDangleAndCauseCrash
|
||||
{
|
||||
NS_VALID_UNTIL_END_OF_SCOPE UIView *host = [[UIView alloc] init];
|
||||
|
||||
__block NS_VALID_UNTIL_END_OF_SCOPE ASDisplayNode *node = [[ASDisplayNode alloc] init];
|
||||
node.layerBacked = YES;
|
||||
|
||||
[host addSubnode:node];
|
||||
[self executeOffThread:^{
|
||||
node = nil;
|
||||
}];
|
||||
host = nil; // <- Would crash here, when UIView accesses its sublayers' delegates in -dealloc.
|
||||
}
|
||||
|
||||
- (void)testThatSubnodeGetsInterfaceStateSetIfRasterized
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user