【问题标题】:ARSKView not releasing memory on dismissing ViewControllerARSKView 在关闭 ViewController 时未释放内存
【发布时间】:2018-12-09 13:25:24
【问题描述】:

我正在创建一个使用 ARSKView 的应用程序。我看到它在关闭 ViewController 时没有释放内存。我在我的代码中找不到任何问题。 这是我使用 ARSKView 的代码。

class ARViewController: UIViewController, ARSKViewDelegate {

    weak var sceneView: ARSKView?

    override func viewDidLoad() {
        super.viewDidLoad()
        sceneView = ARSKView(frame: self.view.frame)
        self.view.addSubview(sceneView!)
        sceneView?.delegate = self

        let scene = CustomScene(size: view.frame.size)
        scene.sceneDelegate = self
        sceneView?.presentScene(scene)
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        activateARView()   
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        sceneView?.session.pause()
    }

    var configuration = ARWorldTrackingConfiguration()
    func activateARView() {
        configuration.worldAlignment = .gravityAndHeading
        sceneView?.session.run(configuration)
    }

}

【问题讨论】:

  • 您的场景正在持有视图控制器,而视图控制器的视图正在持有场景。 ARC 无法将 VC 引用计数降至 0 以释放
  • @Knight0fDragon 能否具体说明一下,代码哪里有问题?
  • 已经告诉你了
  • sceneDelegate 很弱。
  • @Knight0fDragon 苹果已经在 iOS 12 中解决了这个问题

标签: ios swift sprite-kit scenekit arkit


【解决方案1】:

控制器刚刚暂停,您可以尝试将控制器设置为“nil”,确保在此之前清除所有依赖项。

【讨论】:

  • 一旦设置为 nil,恐怕就没有什么可做的了,只能等到 iOS 释放内存 如果它在 Xcode 中,你正在监视内存分配,那么可能是 Ccode 问题
猜你喜欢
  • 2018-09-25
  • 2017-02-01
  • 2018-11-08
  • 2018-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-01
  • 1970-01-01
相关资源
最近更新 更多