4

I'm using a ARView to show AR content in my app, but on dismissing the view controller, the memory is not completely deallocated.

I found this question, but I had no luck with the answer.

The memory consumption looks like this:

memory consumption graph

The entire codebase is very simple:

I've got a button that on pressing it, executes this:

    let vc = SecondViewController()
    self.present(vc, animated: true, completion: {
        print("done")
    })

and SecondViewController is a simple as this:

class SecondViewController: UIViewController {
    
    var arView: ARView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.arView = ARView(frame: self.view.frame)
        self.view.addSubview(arView!)
        arView!.automaticallyConfigureSession = true
        
    }
    
    deinit {
        self.arView?.session.pause()
        self.arView?.session.delegate = nil
        self.arView?.scene.anchors.removeAll()
        self.arView?.removeFromSuperview()
        self.arView?.window?.resignKey()
        self.arView = nil
        
    }
}

But on dismissing, as can be seen in the memory graph, the memory is not deallocated fully.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Will
  • 4,942
  • 2
  • 22
  • 47
  • Hi @Will, here's my answer on this topic – https://stackoverflow.com/questions/71678361/why-does-realitykit-memory-does-not-clear-after-deinit-called/71844537#71844537 – Andy Jazz May 16 '22 at 07:35

0 Answers0