美文网首页
SCNNode 内存不释放解决办法

SCNNode 内存不释放解决办法

作者: 张科_Zack | 来源:发表于2021-04-22 14:41 被阅读0次

    原文
    I had the same problem, with my SceneKit app leaking a lot of memory. The memory of the SCNNode is freed if you set its geometry property to nil before letting Swift deinitialize it.

    Here is an example of how you may implement it:

    class ViewController: UIViewController {
        @IBOutlet weak var sceneView: SCNView!
        var scene: SCNScene!
        override func viewDidLoad() {
            super.viewDidLoad()
            scene = SCNScene()
            sceneView.scene = scene
        }
    
        deinit {
            scene.rootNode.cleanup()
        }
    }
    
    extension SCNNode {
        func cleanup() {
            for child in childNodes {
                child.cleanup()
            }
            geometry = nil
        }
    }
    
    
    

    相关文章

      网友评论

          本文标题:SCNNode 内存不释放解决办法

          本文链接:https://www.haomeiwen.com/subject/sftfrltx.html