Potential memory leak in code

前端 未结 2 641
旧巷少年郎
旧巷少年郎 2021-01-14 13:33

In an app I\'m working on, there is a requirement to periodically poll for device\'s data like acceleration, gyro and motion. I wrote the following class to handle all the r

2条回答
  •  半阙折子戏
    2021-01-14 14:04

    You directly access self in blocks, that may cause retain cycle. Try to use weak self like:

    motionDetector?.motionTypeChangedBlock = { [weak self] motionType in
        if motionType == MotionTypeNotMoving {
            self?.isMoving = false
        } else {
            self?.isMoving = true
        }
    }
    

    So does others blocks.

提交回复
热议问题