怀疑关闭的保留周期 [英] Retain cycle suspected in closure
本文介绍了怀疑关闭的保留周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怀疑我在GameScene类中使用以下功能来管理加速度计的输入时,以下功能使我的场景在过渡到另一个场景时不会取消初始化:
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.
推荐答案
您应该像这样将其放在accelerometerData, error in
之前[unowned self] accelerometerData, error in
You should put it before accelerometerData, error in
like this [unowned self] accelerometerData, error in
这篇关于怀疑关闭的保留周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文