[ASDisplayNode] Change _pendingDisplayNodes from NSMutableSet to ASWeakSet. (#2340)

In at least some cases, _pendingDisplayNodes referencing self can cause the
object to live longer than the application needs, while tearing down views.

It also appears there may be a cancellation condition where this state is
not balanced properly, which can cause a reference-cycle leak.  This change
safely fixes this problem when tested against a repro case for it.

I'm filing a followup task to make sure all cancellation edge cases have
proper accounting for this codepath, even though the leak is fixed.
This commit is contained in:
appleguy
2016-10-04 07:22:54 -07:00
committed by Adlai Holler
parent 67045c07b8
commit 360541fac5
2 changed files with 3 additions and 2 deletions

View File

@@ -2235,7 +2235,7 @@ static NSInteger incrementIfFound(NSInteger i) {
ASDisplayNodeAssertMainThread();
if (!_pendingDisplayNodes) {
_pendingDisplayNodes = [[NSMutableSet alloc] init];
_pendingDisplayNodes = [[ASWeakSet alloc] init];
}
[_pendingDisplayNodes addObject:node];

View File

@@ -21,6 +21,7 @@
#import "ASLayoutTransition.h"
#import "ASEnvironment.h"
#import "ASObjectDescriptionHelpers.h"
#import "ASWeakSet.h"
#import "ASDisplayNode+Beta.h"
@@ -145,7 +146,7 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
CALayer *_placeholderLayer;
// keeps track of nodes/subnodes that have not finished display, used with placeholders
NSMutableSet *_pendingDisplayNodes;
ASWeakSet *_pendingDisplayNodes;
ASDisplayNodeContextModifier _willDisplayNodeContentWithRenderingContext;
ASDisplayNodeContextModifier _didDisplayNodeContentWithRenderingContext;