Skip to content

Commit 8968dce

Browse files
authored
Avoid possible retain cycles in animation completion handler on dismissal
In certain conditions after dismissing the controller cpu spikes due to retain cycle animation loop. Set weak self reference in completion block to alleviate.
1 parent 28c52de commit 8968dce

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Sources/BarcodeScannerController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ open class BarcodeScannerController: UIViewController {
112112
self.infoView.frame = self.infoFrame
113113
self.infoView.status = self.status
114114
},
115-
completion: { _ in
115+
completion: { [weak self] _ in
116116
if delayReset {
117-
self.resetState()
117+
self?.resetState()
118118
}
119119

120-
self.infoView.layer.removeAllAnimations()
121-
if self.status.state == .processing {
122-
self.infoView.animateLoading()
120+
self?.infoView.layer.removeAllAnimations()
121+
if self?.status.state == .processing {
122+
self?.infoView.animateLoading()
123123
}
124124
})
125125
}
@@ -378,11 +378,11 @@ open class BarcodeScannerController: UIViewController {
378378
animations: {
379379
flashView.alpha = 0.0
380380
},
381-
completion: { _ in
381+
completion: { [weak self] _ in
382382
flashView.removeFromSuperview()
383383

384384
if whenProcessing {
385-
self.status = Status(state: .processing)
385+
self?.status = Status(state: .processing)
386386
}
387387
})
388388
}

0 commit comments

Comments
 (0)