From c0b3a4510dcbc85cb7b7dc095fd1d44491969ba3 Mon Sep 17 00:00:00 2001 From: Jeremie Marguerie Date: Fri, 17 Nov 2017 15:44:03 -0500 Subject: [PATCH 1/2] Remove cycles that have already been broken down --- .../Detector/FBRetainCycleDetector.mm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm b/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm index b342be1..4ad3a91 100644 --- a/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm +++ b/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm @@ -69,6 +69,21 @@ - (void)addCandidate:(id)candidate [_candidates removeAllObjects]; [_objectSet removeAllObjects]; + // Filter cycles that have been broken down since we found them. + // These are false-positive that were picked-up and are transient cycles. + NSMutableSet *> *remove = [NSMutableSet set]; + for (NSArray *itemCycle in allRetainCycles) { + for (FBObjectiveCGraphElement *element in itemCycle) { + if (element.object == nil) { + // At least one element of the cycle has been removed, thuse breaking + // the cycle. + [remove addObject:itemCycle]; + break; + } + } + } + [allRetainCycles minusSet:remove]; + return allRetainCycles; } From ea662c4fbfa958314429b551a7c7bee476844c5a Mon Sep 17 00:00:00 2001 From: Brennan Vincent Date: Thu, 14 Sep 2017 14:45:46 -0400 Subject: [PATCH 2/2] Allow custom traversal logic via a user-supplied block --- FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm | 8 ++++---- FBRetainCycleDetector/Graph/FBObjectiveCBlock.m | 2 +- FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm b/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm index 4ad3a91..b340943 100644 --- a/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm +++ b/FBRetainCycleDetector/Detector/FBRetainCycleDetector.mm @@ -71,18 +71,18 @@ - (void)addCandidate:(id)candidate // Filter cycles that have been broken down since we found them. // These are false-positive that were picked-up and are transient cycles. - NSMutableSet *> *remove = [NSMutableSet set]; + NSMutableSet *> *brokenCycles = [NSMutableSet set]; for (NSArray *itemCycle in allRetainCycles) { for (FBObjectiveCGraphElement *element in itemCycle) { if (element.object == nil) { - // At least one element of the cycle has been removed, thuse breaking + // At least one element of the cycle has been removed, thus breaking // the cycle. - [remove addObject:itemCycle]; + [brokenCycles addObject:itemCycle]; break; } } } - [allRetainCycles minusSet:remove]; + [allRetainCycles minusSet:brokenCycles]; return allRetainCycles; } diff --git a/FBRetainCycleDetector/Graph/FBObjectiveCBlock.m b/FBRetainCycleDetector/Graph/FBObjectiveCBlock.m index cee0dea..7097999 100644 --- a/FBRetainCycleDetector/Graph/FBObjectiveCBlock.m +++ b/FBRetainCycleDetector/Graph/FBObjectiveCBlock.m @@ -72,7 +72,7 @@ - (NSString *)classNameOrNull { NSString *className = NSStringFromClass([self objectClass]); if (!className) { - className = @"Null"; + className = @"(null)"; } if (!self.configuration.shouldIncludeBlockAddress) { diff --git a/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm b/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm index 636e2b0..c9015ab 100644 --- a/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm +++ b/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm @@ -116,7 +116,7 @@ - (NSString *)classNameOrNull { NSString *className = NSStringFromClass([self objectClass]); if (!className) { - className = @"Null"; + className = @"(null)"; } return className;