Retain cycle suspected in closure

余生长醉 提交于 2019-12-14 02:26:34

问题


I suspect that the following function, which I use in my GameScene class in order to manage the accelerometer's input, is keeping my scene from deinitializing when I transition to another scene:

class GameScene: SKScene {
    let motionManager = CMMotionManager()
    var xAcceleration = CGFloat(0)
    // Some stuff
    // override func didMove(to: ....

    func setupCoreMotion() {
        motionManager.accelerometerUpdateInterval = 0.2
        let queue = OperationQueue()
        motionManager.startAccelerometerUpdates(to: queue,
                                                withHandler:
            {
                accelerometerData, error in
                guard let accelerometerData = accelerometerData else {
                    return
                }
                let acceleration = accelerometerData.acceleration
                self.xAcceleration = (CGFloat(acceleration.x) * 0.75) +
                    (self.xAcceleration * 0.25)
        })
    }
}

It may be because of the self capture, but if that's the case, I have no clue where to put the "[unowned self] in" capture list.


回答1:


You should put it before accelerometerData, error in like this [unowned self] accelerometerData, error in



来源:https://stackoverflow.com/questions/42028982/retain-cycle-suspected-in-closure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!