[swift-users] UINavigationController subclass leaks member variable memory

吴君恺 wjk_buaa at 163.com
Thu Dec 14 01:05:06 CST 2017


Hello community, 

	I just encountered a pretty weird behavior when I subclass  `UINavigationController` without overriding any initializers.

Simple Code:

import UIKit

class MyViewController: UINavigationController {
  
  let value: Int = {
    print("member init")
    return 3
  }()
}

let _ = MyViewController(rootViewController: UIViewController())

output is:

member init
member init

In fact any member variables declared in this subclass is initialized twice but deinitialized only once.
This phenomenon only appears when using `init(rootViewController:)`. 

CMIW, It looks like Swift somehow treat this initializer as a designated initializer, rather than a convenience one. 

Any Ideas?






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171214/6bdc89f8/attachment.html>


More information about the swift-users mailing list