From a26128269fc467b511b143ba089b8bc0aaa6cd51 Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Sun, 23 Feb 2025 15:58:05 -0800 Subject: [PATCH 1/3] Reinstate flow controller deinit assertion --- Sources/Nodes/Internal/FlowController.swift | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sources/Nodes/Internal/FlowController.swift b/Sources/Nodes/Internal/FlowController.swift index 538702b69..8c55e2003 100644 --- a/Sources/Nodes/Internal/FlowController.swift +++ b/Sources/Nodes/Internal/FlowController.swift @@ -30,6 +30,12 @@ public final class FlowController { internal var isFlowLeakDetectionEnabled: Bool = true + #if DEBUG + + private var _flowCount: Int = 0 + + #endif + /// Initializes a new ``FlowController`` instance to manage a collection of `Flow` instances. public init() {} @@ -68,6 +74,9 @@ public final class FlowController { DebugInformation.FlowControllerWillAttachNotification(flowController: self, flow: flow).post() #endif flows.append(flow) + #if DEBUG + _flowCount += 1 + #endif flow.start() } @@ -84,6 +93,9 @@ public final class FlowController { return } flow.end() + #if DEBUG + _flowCount -= 1 + #endif flows.removeAll { $0 === flow } if isFlowLeakDetectionEnabled { LeakDetector.detect(flow) } #if DEBUG @@ -234,4 +246,16 @@ public final class FlowController { public func withFlows(ofType type: T.Type, perform: (_ flow: T) throws -> Void) rethrows { try flows(ofType: type).forEach(perform) } + + #if DEBUG + + deinit { + if _flowCount > 0 { + assertionFailure(""" + Lifecycle Violation: Expected `Flow` instances to be detached before `FlowController` is deallocated + """) + } + } + + #endif } From 0ad6b32e24bc660115da8352f7519b97ef664428 Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Sun, 23 Feb 2025 16:09:10 -0800 Subject: [PATCH 2/3] Revise message --- Sources/Nodes/Internal/FlowController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Nodes/Internal/FlowController.swift b/Sources/Nodes/Internal/FlowController.swift index 8c55e2003..1f46afce8 100644 --- a/Sources/Nodes/Internal/FlowController.swift +++ b/Sources/Nodes/Internal/FlowController.swift @@ -252,7 +252,7 @@ public final class FlowController { deinit { if _flowCount > 0 { assertionFailure(""" - Lifecycle Violation: Expected `Flow` instances to be detached before `FlowController` is deallocated + Lifecycle Violation: Expect `Flow` instances to be detached before `FlowController` is deallocated. """) } } From dbdc4a5f9ed5618f82e810c7ac895c063ceeae5a Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Sun, 23 Feb 2025 16:13:26 -0800 Subject: [PATCH 3/3] Revise message --- Sources/Nodes/Internal/FlowController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Nodes/Internal/FlowController.swift b/Sources/Nodes/Internal/FlowController.swift index 1f46afce8..60371ff6e 100644 --- a/Sources/Nodes/Internal/FlowController.swift +++ b/Sources/Nodes/Internal/FlowController.swift @@ -252,7 +252,7 @@ public final class FlowController { deinit { if _flowCount > 0 { assertionFailure(""" - Lifecycle Violation: Expect `Flow` instances to be detached before `FlowController` is deallocated. + Lifecycle Violation: Expect `Flow` instances to detach before `FlowController` is deallocated. """) } }