2

Here is my code:

ship.runAction(SKAction.waitForDuration(5), completion: {
    self.ship.flyStraight()//retain self
})

After several days googling for the memory issues, finally I found that I had a self retain in this block. When I create the new scene before the block has run, the deinit function won't be called because the reference in the block.

I have to write in this way in my game, and what can I do to avoid this issue. What did you with code like this?

4

1 に答える 1

6

同じ問題を抱えている人のために。コードを次のように変更しました。

ship.runAction(SKAction.waitForDuration(5), completion: {
        [unowned self] in
        self.ship.flyStraight()        
    })

ブロックで使用[unowned self] inしても、自己への強い参照は追加されません。

マーティンのリンクに感謝します:「閉鎖のための強力な参照サイクルの解決」

この質問を見ることもできます

于 2015-01-26T06:13:14.327 に答える