title: SwiftUI memory leak when using UIViewControllerRepresentable
body: <p><strong><em>UPDATE: As of beta4, problem still present.</em></strong></p>
  
  <p>I have created a very simple example of how a UIViewController represented by UIViewControllerRepresentable is <strong>never</strong> deallocated.</p>
  
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  
  struct ContentView : View {
      @State private var showRepView = true
  
      var body: some View {
          VStack {
              Text("Square").font(.largeTitle).tapAction {
                  self.showRepView.toggle()
              }
  
              if showRepView {
                  SomeRepView().frame(width: 100, height: 100)
              }
          }
  
      }
  }
  </code></pre>
  
  <p>The representation implementation follows:</p>
  
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  
  struct SomeRepView: View {
      var body: some View {
          RepViewController()
      }
  }
  
  struct RepViewController: UIViewControllerRepresentable
  {
      func makeUIViewController(context: Context) -&gt; SomeCustomeUIViewController {
          let vc =  SomeCustomeUIViewController()
          print("INIT \(vc)")
          return vc
      }
  
      func updateUIViewController(_ uiViewController: SomeCustomeUIViewController, context: Context) {
      }
  
      static func dismantleUIViewController(_ uiViewController: SomeCustomeUIViewController, coordinator: Self.Coordinator) {
          print("DISMANTLE")
      }
  
  }
  
  class SomeCustomeUIViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          view.backgroundColor = UIColor.green
      }
  
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
          print("viewWillDissapear \(self)")
      }
  
      deinit {
          print("DEINIT \(self)")
      }
  
  }
  </code></pre>
  
  <p>By tapping on the "Square" button, <code>SomeRepView</code> is added and removed alternatively. However, the related UIViewController is never released. That can be seen by the logged messages and I also confirmed with Instruments.</p>
  
  <p>Note that SomeRepView is released properly. It is only the corresponding view controller what remains allocated.</p>
  
  <p>Also note that the <code>UIViewController.viewWillDissappear</code> is called and also the <code>UIViewControllerRepresentable.dismantleUIViewController</code></p>
  
  <p>This is a typical output of pressing the Square button repeatedly.</p>
  
  <pre><code>INIT &lt;SomeCustomeUIViewController: 0x100b1af70&gt;
  DISMANTLE
  viewWillDissapear &lt;SomeCustomeUIViewController: 0x100b1af70&gt;
  INIT &lt;SomeCustomeUIViewController: 0x100a0a8c0&gt;
  DISMANTLE
  viewWillDissapear &lt;SomeCustomeUIViewController: 0x100a0a8c0&gt;
  INIT &lt;SomeCustomeUIViewController: 0x100b23690&gt;
  DISMANTLE
  viewWillDissapear &lt;SomeCustomeUIViewController: 0x100b23690&gt;
  </code></pre>
  
  <p>As show, <code>DEINIT</code> is never printed.</p>
  
  <p>My question is... is it a bug? Or am I doing something wrong?</p>
  
  <p>Running with iOS13, beta 4.</p>
  
  <p>I tried triggering <strong>Simulate Memory Warning</strong>. No effect. The controllers persist. Instruments is my witness ;-)</p>