Skip to content

Leak when running with Host Application #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

llinardos
Copy link
Contributor

@llinardos llinardos commented Sep 8, 2021

Fixes #510

The cause of the leak is in the issue description 👆
The fix: By removing the view controller from its parent when the test finishes, no one retains the view controller, fixing the leak.

The same demo project that's in the issue using a branch with the fix: SnapshotTestingLeakDemo-Fixed.zip

It would be great to have this automated, but it requires a new test target that uses a host application (and also a target for the host application). I'm open to doing that, but it's adding targets to the project, not sure if you want that.

@llinardos llinardos changed the title When running with host application, rootViewController is retained by… Leak when running with Host Application Sep 8, 2021
viewController.willMove(toParent: nil)
viewController.view.removeFromSuperview()
viewController.removeFromParent()
viewController.didMove(toParent: nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refactor your PR so this is the only change? We'd like to keep the project file and project.yml as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@llinardos llinardos force-pushed the fix-memory-leak-when-running-with-host-application branch from 5c9aeb6 to 77f2b15 Compare January 10, 2022 15:54
Copy link
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@stephencelis stephencelis merged commit 88f6e2c into pointfreeco:main Jan 11, 2022
niil-qb pushed a commit to quickbit/swift-snapshot-testing that referenced this pull request Feb 23, 2023
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.
OksanaFedorchuk pushed a commit to urlaunched-com/swift-snapshot-testing that referenced this pull request Mar 28, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leak when running with host application
2 participants