Skip to content

Commit 503d083

Browse files
committed
Future now clears cycle nodes more aggressively, and has a comment that it's okay if they aren't
1 parent 5238e04 commit 503d083

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: src/TOCFutureAndSource.m

+9-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ -(enum StartUnwrapResult) _ForSource_tryStartUnwrapping:(TOCFuture*)targetFuture
8484
// look for flattening cycles
8585
@synchronized(getSharedCycleDetectionLock()) {
8686
bool didMerge = [self._getInitCycleNode unionWith:targetFuture._getInitCycleNode];
87-
if (!didMerge) return StartUnwrapResult_CycleDetected;
87+
if (!didMerge) {
88+
// it's not necessary to clear the cycle nodes, but it frees up some memory
89+
// other futures in the cycle won't get their cycle nodes cleared
90+
// but node chains should be in EXTREMELY shallow trees
91+
// and the nodes can't keep futures alive, so there's no reference cycle
92+
_cycleNode = nil;
93+
targetFuture->_cycleNode = nil;
94+
return StartUnwrapResult_CycleDetected;
95+
}
8896
}
8997

9098
return StartUnwrapResult_Started;

0 commit comments

Comments
 (0)