Open mixerzeyu opened 4 years ago
Hi!
Thank you for shedding some light on this issue! I just profiled the example project on this repo and you're right, there seems to be a minor leak when the UIViewController is supposedly deallocated. I haven't analyzed it in depth yet, but it does seem to be a circular reference as you speculated! I'll make sure to fix it in the next release once I get a chance.
Thanks again!
Hi!
The problem is in MSCircularSlider:
func initHandle() {
handle.delegate = self
handle.center = {
return self.pointOnCircleAt(angle: self.angle)
}
}
self in closure creates retain cycle. We should use capture list here:
func initHandle() { handle.delegate = self handle.center = { [weak self] in guard let self = self else { return CGPoint(x: 0, y: 0) } return self.pointOnCircleAt(angle: self.angle) } }
Hey @Vasyltm
You're absolutely right! The self reference in the closure does in fact create a retain cycle. Thanks for the proposed solution as well. Will include it in the next update (and credit you in the changelog)!
@Vasyltm Thanks so much for posting the solution - it works like a charm! @ThunderStruct Would be great to know once this fix goes is updated :)
Hi - The circular slider is amazing!
I've noticed recently it does not cleanup properly and creates memory leaks. There seems to be a circular (no pun intended) reference somewhere within the controller, therefore it is not deallocated when the containing UIViewController exits.
You can see the memory leaks if you show memory graphs when running an Xcode project in debug mode, there would be multiple instances of the circular slider created after you open and close the UIViewController multiple times.
Let me know if you need more info.
Thanks!