4

I'm facing an issue with the RAM management on the view which uses Reality Kit. There I have a simple code that reproduces the issue. Before open AR view the app takes about 70MB of RAM, after running AR view, then it takes about 450MB RAM, but when I dismiss the AR, then the whole app takes about 250MB RAM, so it's like 130MB more of unused data from AR. https://i.stack.imgur.com/3oQym.png how I can clean that? I used Xcode tools to detect leaks, but on that tool everything is okay. How I can solve it?

override func viewDidLoad() {
     super.viewDidLoad()
     arView = ARView(frame: self.view.bounds)
     self.view.addSubview(arView!)
     self.view.sendSubviewToBack(arView!)
}

@IBAction func dimissTapped(_ sender: Any) {
     self.arView?.session.pause()
     self.arView?.session.delegate = nil
     self.arView?.scene.anchors.removeAll()
     self.arView?.removeFromSuperview()
     self.arView?.window?.resignKey()
     self.arView = nil
     self.dismiss(animated: true, completion: nil)
}


  [1]: https://i.stack.imgur.com/3oQym.png
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • Try to run `Instruments`, or `Memory Graph`, to see full picture of the problem. – vpoltave Oct 02 '20 at 13:51
  • It's doesn't help in any way. I did the simplest possible view with ARView, and still the same issue, the app has 200MB+ after presnet/dimiss AR – Marcin Kaczmarzyk Oct 08 '20 at 20:17
  • Than, you can file a report here: https://developer.apple.com/bug-reporting/ and wait for the response from Apple team. – vpoltave Oct 08 '20 at 20:35
  • Hi @MarcinKaczmarzyk, 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:26
  • I don't think there is supposed to be a workaround. This is because the memory from an old ARView has similar properties as a new ARView you might instantiate in the future. I guess it's just to make the ARView load faster when doing repeated AR tasks with different or reusing ARViews. I have noticed that if I repeatedly instantiate one ARView after ending the previous one, the memory usage does not increase and stays relatively the same. – Bhavin p Jan 11 '23 at 21:01

0 Answers0