I cannot manage to release my RealityKit ARView() from memory.
I am aware that there are (were?) similar issues with ARKit + SceneKit – with workarounds like this one: https://stackoverflow.com/a/53919730/7826293 which doesen´t solve my problem unfortunately.
The solutions above kind of work by removing everything "suspicious" manually. That is exactly what I did in a even wider scope:
class ViewController_ARViewMemoryTest: UIViewController {
    var arView: ARView?
    init() {
        super.init(nibName: nil, bundle: nil)
        arView = ARView(frame: .zero)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    deinit {
        doEverythingThatsNeeded()
    }
    public func doEverythingThatsNeeded() {
        self.arView?.session.pause()
        self.arView?.session.delegate = nil
        self.arView?.removeFromSuperview()
        // Quite a few more removals and resets here, ie. for Combines AnyCancellables
        self.arView = nil
    }
}
I am calling doEverythingThatsNeeded() from outside as well:
aRViewMemoryTest?.doEverythingThatsNeeded()
aRViewMemoryTest?.arView = nil
aRViewMemoryTest = nil
The issue seems to be independent from the fact that I have wrapped my ARView or alternatively a UIViewController in a SwiftUI UIViewRepresentable / UIViewControllerRepresentable.
I believe it must be a bug and I have filed a report months ago. However I am hoping for workarounds that help until Apple fixes the potential issue.
Thanks a lot!
