Number of meshes keeps growing

I have an iOS application where I


(1) select a model to view in a list view in a navigation controller, and then segue to a view controller with an ARView to display the model

(2) I can then go back to the list view controller, select a different model, which then segues back to the view controller with the ARView


The new view controller with the ARView is loaded each time and deallocated each time I go back to select another model to view (I print("") with init?(), viewDidLoad(), and deinit)


I have the showStatistics turned of for the ARView:

arView.debugOptions = .showStatistics


I am seeing the Mesh count (Scene Mesh Stats: Meshes: from the debug stats) climb each time I exit the view controller and then reload it with another model (or the same one).


After doing this round trip several times (and growing the meshes), the frames per seconds start to drop


It seems as if while the view controller holding the ARView is allocated new and deallocated each round trip, the Meshes from the pprevious models are sticking around in the Metal pipeline or something. (I've never worked with Metal directly, and I am relatively new to ARKit & RealityKit).


Is that what is happening? If so, is there a command to flush the old meshes when I first load my view controller?


Thanks.

Accepted Reply

I took a cue from this old thread


https://forums.developer.apple.com/thread/80337


and built a very simplified UIViewController with an ARView and repeatedly went back and forth loading and unloading the view and displaying my somewhat complex model.


Everything worked fine, so the problem in my larger program is clearly mine. I suspect my code is complex enough that I have one or more accidental retain cycles going on.


I am going to close this thread.

Replies

A quick update.


I have found that if in the ViewController with my ARView I override viewWillDisappear(_ animated: Bool) and remove the anchors added to the scene before the scene disappears, then the meshes do drop back down to normal when I reload the ViewController


E.g.,

self.arView.scene.removeAnchor(self.worldAnchor!)


where worldAnchor is the root anchor for most of my content.


HOWEVER, eventually FPS does drop even though the mesh count is low again. That is, the more times I reload the ViewController with the ARView, the slower the FPS becomes.


So I still don't know how to correct for that.

I took a cue from this old thread


https://forums.developer.apple.com/thread/80337


and built a very simplified UIViewController with an ARView and repeatedly went back and forth loading and unloading the view and displaying my somewhat complex model.


Everything worked fine, so the problem in my larger program is clearly mine. I suspect my code is complex enough that I have one or more accidental retain cycles going on.


I am going to close this thread.