Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9400

Mirror make memory leak if children access to IBOutlet

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: None
    • Labels:
      None
    • Environment:

      Xcode: Version 10.1 (10B61)
      Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
      Target: x86_64-apple-darwin17.7.0

      Description

      Minimum swift code is next one.

      import UIKit
      
      class Label: UILabel {
          deinit {
              print("deinit label")
          }
      }
      
      class NotLeakViewController1: UIViewController {
          @IBOutlet weak var label: Label!
          override func viewDidLoad() {
              super.viewDidLoad()
          }
      }
      
      class NotLeakViewController2: UIViewController {
          var label: Label = Label()
          override func viewDidLoad() {
              super.viewDidLoad()
              view.addSubview(label)
              _ = Array(Mirror(reflecting: self).children) // Iterate mirror children
          }
      }
      
      class LeakViewController: UIViewController {
          @IBOutlet weak var label: Label!
          override func viewDidLoad() {
              super.viewDidLoad()
              _ = Array(Mirror(reflecting: self).children) // Iterate mirror children
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              tarunon Nobuo Saito
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: