Reality Kit ARView instantiation

Premise

I'm writing an app (SwiftUI/RealityKit) in which I instantiate ARview directly in code inside ARViewContainer: UIViewRepresentable - as per template (I don't use RealityComposer).
The management of the AR in my application is the endpoint of a Navigation, so the user enters and exits the AR scenes multiple times, changing a series of parameters each time.

Problem
I noticed that every time arView is created, the system generates a different name for the Scene (automatically generated and assigned to the ARView): scene-1, scene-2, ..., scene-n.

Question
Is this normal, or does it mean that by recreating the ARView object several times the individual scenes remain in memory (generating something that could be a memory leak)?

The same thing happens if I move the declaration of the arView variable as a global fileprivate in the source (which would be much better for me, to be able to access the arView object from multiple parts of the code).

Is this behavior in the name of the scenes normal? Or am I causing a problem in some way? And if so, what is the right procedure to follow?

Thank you very much,
Alessandro
Hello,

What you have described is normal, and only problematic if you were relying on the default name of the Scene being something specific (which you should not do since the behavior of the default Scene name is not documented).

If you run your sample project in Instruments using the Allocations instrument, you should be able to see the number of persistent Scene objects by filtering for "Scene". If you were leaking these objects, you would see the persistent count for these objects increasing as you presented and dismissed your view several times. If you are not leaking, the persistent count will remain at 1.
Reality Kit ARView instantiation
 
 
Q