applidium/OverlayContainer

Memory leak

fanglinwei opened this issue · 5 comments

Describe the bug
A clear and concise description of what the bug is.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots, videos or sample codes
If applicable, add screenshots to help explain your problem.

Environnement :

  • Device: iPhoneX
  • OS: iOS 13.6
  • OverlayContainer Version 3.5.0

Additional context
Add any other context about the problem here.

image

window?.rootViewController = UINavigationController(rootViewController: TestViewController())
navigationController?.pushViewController(ShowOverlayExampleViewController(), animated: true)

ShowOverlayExampleViewController popViewController deinit does not execute

image

when do you pop your view controller?

when do you pop your view controller?

When I clicked the system launch button pop ShowOverlayExampleViewController in the upper left corner, I found that ShowOverlayExampleViewController did not execute deinit.

when do you pop your view controller?

My simple guess is that overlayPresentationController may cause memory leaks

Interesting. The leak exists as soon as you call presentationController:

class TestViewController: UIViewController {

    // MARK: - Life Cycle

    init() {
        super.init(nibName: nil, bundle: nil)
        view.backgroundColor = .systemRed
    }

    @available(*, unavailable)
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        let controller = PushedViewController()
        let presentationController = controller.presentationController
        navigationController?.pushViewController(controller, animated: true)
    }
}

class PushedViewController: UIViewController {

    // MARK: - Life Cycle

    init() {
        super.init(nibName: nil, bundle: nil)
        view.backgroundColor = .systemBlue
    }

    deinit {
        print("Deinit") // never called
    }

    @available(*, unavailable)
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
} 

Here is a fix. I don't like it but I will release it if I do not find something better. Thanks for pointing me the issue! It is critical.