PaoloCuscela / Cards

Awesome iOS 11 appstore cards in swift 5.
MIT License
4.2k stars 274 forks source link

strong reference cycle. superVC deinit is never called #61

Closed anatolyw closed 6 years ago

anatolyw commented 6 years ago

In my setup I hold Card reference inside another ViewController, so schematically the code looks like follow:

    class MyAlert: UIViewController {
        public var customView: UIView? = nil  // here I hold my Card
    }

    class MyTableViewController {
        deinit {
            print("MyTableViewController: deinit")
        }

        func showAlertWithCard {

            let card = CardHighlight(frame: CGRect(x: 10, y: 0, width: screenSize.width-20 , height: 240.0 ))
            card.icon = UIImage(named: "flappy")
            card.title = "Welcome \nto \nCards !"
            card.itemTitle = "Flappy Bird"
            card.itemSubtitle = "Flap That !"
            card.textColor = UIColor.white
            card.hasParallax = true

            let cardContentVC = storyboard!.instantiateViewController(withIdentifier: "CardContent")
            card.shouldPresent(cardContentVC, from: self, fullscreen: false)

            let alert = MyAlert()
            alert.showInView = self.view
            alert.customView = card
            alert.show()
        }

    }

unfortunately deinit on MyTableViewController is never called until I change the definition of suprVC inside Card class from strong (default) to weak as follow:

weak var superVC: UIViewController?

Would be nice to have this fix it in the official code without need to patch it locally.

PaoloCuscela commented 6 years ago

Done in the @kietnim commit 👍