MihaelIsaev / UIKitPlus

🏰 Declarative UIKit with LivePreview for iOS9+ (best alternative to SwiftUI)
MIT License
596 stars 35 forks source link

leadingToSuperview method can cause memory leak #20

Closed EkkoG closed 2 years ago

EkkoG commented 2 years ago

POC

class TestView: UIView {
    deinit {
        print("TView deinit")
    }
}

class TestText: UText {
    deinit {
        print("testText deinit")
    }
}

class TestVC: UIViewController {
    deinit {
        print("testvc deinit")
    }

    override func loadView() {
        view = TestView()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        view.body {
            TestText().leadingToSuperview()
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            self.navigationController?.popViewController(animated: true)
        }
    }
}
EkkoG commented 2 years ago

The reason is this line of code https://github.com/MihaelIsaev/UIKitPlus/blob/19c2c4f69d5bb5de22af4fb68c466d67cca746b7/Classes/Extensions/DeclarativeProtocol%2BConstraintsSuper.swift#L392