相关疑难解决方法(0)

使用捕获列表中的无主内容导致崩溃,甚至块本身也不会被执行

在这里,我正在玩泄漏,所以我有意识地做了一个强大的参考周期,看看仪器是否会检测到某些东西,我得到了意想不到的结果.仪器中显示的泄漏确实有意义,但随机崩溃有点神秘(由于我将在后面提到的两个事实).

我这里有一个叫做的课程SomeClass:

class SomeClass{

    //As you can guess, I will use this shady property to make a strong cycle :)
    var closure:(()->())?
    init(){}
    func method(){}
    deinit {print("SomeClass deinited")}
}
Run Code Online (Sandbox Code Playgroud)

我还有两个场景,GameScene:

class GameScene: SKScene {

    override func didMoveToView(view: SKView) {

        backgroundColor = .blackColor()

        let someInstance = SomeClass()

        let closure = {[unowned self] in

            someInstance.method() //This causes the strong reference cycle...
            self.method()  
        }
        someInstance.closure = closure
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

        if …
Run Code Online (Sandbox Code Playgroud)

memory-leaks ios automatic-ref-counting sprite-kit swift

7
推荐指数
1
解决办法
436
查看次数