Post marked as unsolved
Click to stop watching this post.
You have stopped watching this post. Click to start watching again.
Post marked as unsolved with 0 replies
41
Views
ARKit Reset Session Memory Leak
I've been working with ARKit recently while doing some memory leak profiling and noticed that when resetting (calling .run again) the ARSession using the .resetTracking option, there is a memory leak that the Leaks tool reports as coming from somewhere to do with vImageMapping_CreateFromMap_Image8U. I'm not sure if it is something that I'm doing incorrectly or if it an issue on ARKit's side.
Here is a simple code snippet of the SceneKit ViewController setup (modified from an Apple sample):
override func viewDidLoad() {
super.viewDidLoad()
let button:UIButton = UIButton(frame: CGRect(x: 100, y: 400, width: 100, height: 50))
button.backgroundColor = UIColor.black
button.setTitle("Reset", for: .normal)
button.addTarget(self, action:#selector(self.buttonClicked), for: .touchUpInside)
self.view.addSubview(button)
sceneView.delegate = self
sceneView.session.delegate = self
}
@objc func buttonClicked() {
resetTracking()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
resetTracking()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
session.pause()
}
func resetTracking() {
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.horizontal, .vertical]
if #available(iOS 12.0, *) {
configuration.environmentTexturing = .automatic
}
session.run(configuration, options: [.resetTracking])
}
To recreate, Start the app (can snapshot a memory profile here to see there are no leaks),
hit the "reset" button we've created,
generate a memory profile
In the profile, there is an indication that there is a 409600 byte-malloc block that has leaked for every reset.