title: ARKit Reset Session Memory Leak
body: <p>I've been working with ARKit recently while doing some memory leak profiling and noticed that when resetting (calling <code>.run</code> again) the ARSession using the <code>.resetTracking</code> option, there is a memory leak that the Leaks tool reports as coming from somewhere to do with <code>vImageMapping_CreateFromMap_Image8U</code>. I'm not sure if it is something that I'm doing incorrectly or if it an issue on ARKit's side.</p>
  <p>Here is a simple code snippet of the SceneKit ViewController setup (modified from an Apple sample):</p>
  <pre><code>     override func viewDidLoad() {
          super.viewDidLoad()
  
          let button:UIButton = UIButton(frame: CGRect(x: 100, y: 400, width: 100, height: 50))
          button.backgroundColor = UIColor.black
          button.setTitle(&quot;Reset&quot;, for: .normal)
          button.addTarget(self, action:#selector(self.buttonClicked), for: .touchUpInside)
          self.view.addSubview(button)
  
          sceneView.delegate = self
          sceneView.session.delegate = self
      }
  
      @objc func buttonClicked() {
          resetTracking()
      }
  
      override func viewDidAppear(_ animated: Bool) {
          super.viewDidAppear(animated)
  
          resetTracking()
      }
  
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
  
          session.pause()
      }
  
      func resetTracking() {
          let configuration = ARWorldTrackingConfiguration()
          configuration.planeDetection = [.horizontal, .vertical]
          if #available(iOS 12.0, *) {
              configuration.environmentTexturing = .automatic
          }
          session.run(configuration, options: [.resetTracking]) 
      }
  </code></pre>
  <p>To recreate,</p>
  <ol>
  <li>Start the app (can snapshot a memory profile here to see there are no leaks),</li>
  <li>hit the &quot;reset&quot; button we've created,</li>
  <li>generate a memory profile</li>
  </ol>
  <p>In the profile, there is an indication that there is a 409600 byte-malloc block that has leaked for every reset. <a href="https://i.stack.imgur.com/cQmES.png" rel="nofollow noreferrer">Image of the leak in the profiling tool</a></p>