Why does RealityKit memory does not clear after deinit called?
Tested in Xcode 14.0...
Alas, RealityKit 2.0 / 1.0 developers can't deallocate ARView
from heap memory because there is a poor-quality implementation on Apple's part. Even if you declare arView
property as weak
in SwiftUI, this instance will be immediately deallocated, so you can't use it. In UIKit, however, declaring arView
as weak
has no effect.
As you remember, ARC was firstly introduced in Objective-C and later implemented in Swift. It's quite possible that the weak
and unowned
functionality is not implemented for ARView for some reason, perhaps because RealityKit is tailored for Swift only – @objc
attribute explicitly states this. It looks like ARView reference isn't tracked by ARC.
@available(macOS 10.15, iOS 13.0, *)
@objc open class ARView : ARViewBase { ... }
If you need more info, please read this post for details.
Swift ARKit How do you fully kill an ARSession?
Officially, right now, you can't.
However, there is a work-around: you make the ARSCNView
disposable.
On leaving AR, first pause the ARSession
. Then deallocate the entire ARSCNView
hierarchy & set ARSCNView
to nil
for good measure. Rebuild the entire ARSCNView
hierarchy and start a new session whenever you need to go back to AR.
var ARview: ARSCNView?
func punchTheClown() {
ARView?.session.pause()
ARView?.removeFromSuperview()
ARView = nil
}
Other non-AR areas of your app would typically be in a separate view hierarchy at the same sibling level as your ARSCNView
. I look forward to Apple providing an actual stopSession()
function, so we can all stop having to punchTheClown in the meantime.
iOS - Memory usage constantly grows even though no memory leaks shown for actual app (SpriteKit App)
Ok so it turns out the issue is an Apple Bug when 'showsPhysics' is enabled. Turning this off immediately fixed my problem. Thanks @SklyerLauren.
Why ARGeoTrackingConfiguration is not available everywhere?
That's because ARGeoTrackingConfig
doesn't use Google Maps. Apple runs its own LiDAR-equipped vehicles for digitizing cities to supply Apple Maps with all necessary information stored on Apple servers. That info contains precise GPS coordinates and Machine Learning mlmodel
that visually recognises every pre-digitized location. And that specific info is indispensable when you're running ARKit's app with geo anchors.
At the moment only several US cities are available for seeding ARGeoAnchors. However, in 2021 some European and Asian cities will be available for ARKit's geo anchoring as well.
Look at this post to find out how to implement ARGeoTrackingConfig
.
Related Topics
Create View Based Nstableview Programmatically Using Bindings in Swift
Swiftui: How to Make a Button Open a Url in Safari
How to Implement Protocol Methods That Return Covariant Selfs
Load Desktop Version Wkwebview iOS 9
Enumerate Is Unavailable Call the Enumerate Method on the Sequence
Find Multiple Quoted Words in a String with Regex
How to Declare a Class Level Function in Swift
Singleton and Init with Parameter
Lazy Property Initialization in Swift
How to Open a Screen Directly in Xcuitest
Possible to Pass an Enum Type Name as an Argument in Swift
Using Uiapplicationdelegateadaptor to Get Callbacks from Userdidacceptcloudkitsharewith Not Working
Controlling Size of Texteditor in Swiftui