Skip to content

Commit 6ef671b

Browse files
llinardosOksanaFedorchuk
authored andcommitted
Fix leak releasing child view controller. (pointfreeco#511)
When running with host application, rootViewController is retained by the window, and it retains the view controller we are testing (which is a child view controller). This causes a leak on the view controller we're testing. By removing the view controller from it's parent, no one retains the view controller, fixing the leak.
1 parent bab6055 commit 6ef671b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Sources/SnapshotTesting/Common/View.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ private func add(traits: UITraitCollection, viewController: UIViewController, to
941941

942942
return {
943943
rootViewController.beginAppearanceTransition(false, animated: false)
944+
viewController.willMove(toParent: nil)
945+
viewController.view.removeFromSuperview()
946+
viewController.removeFromParent()
947+
viewController.didMove(toParent: nil)
944948
rootViewController.endAppearanceTransition()
945949
window.rootViewController = nil
946950
}

0 commit comments

Comments
 (0)