Why is there memory leak / retain cycle after the action closure of UIDynamicBehavior is called?
stackoverflow.com/questions/54493876/why-is-t...Posted Feb 2, 2019, 2:19 PM UTC
Posted Feb 2, 2019, 2:19 PM UTC
[removed]
Just as a house keeping thing, try and avoid abbreviations for variable names
As a rule I keep my variable name lengths directly proportional to how far away from their declaration they are used.
If you're creating a view controller and immediately pushing it on the nav stack it's OK to call it vc.
If it's private to a small class a single word can be appropriate.
If it's a property that is going to be accessed from outside the class it'd better be named clearly.
Dear predecessor,
I would prefer you to be at least consistent when you screw up your variable names.
Sincerely,
The axe murderer that is going to maintain your code
Exactly this. I don't see anything wrong with using short variable names when they're really narrowly scoped and used right away.
I don't do it, because of the current code standards at this client. But my preference is to keep such names brief.
Maybe its just me, but i'd always rather see a fully expanded variable name. I think its just much much easier to read. I don't know what the advantage of shortened names is
Thanks. In practice I use abbreviations only for locals. I use abbreviations here because the code snippet is not very long:-)
Many of us may be considering using a [weak self] here. But that won't help.
You have a strong reference to self in the action closure. Add ”[weak self] in”
I've run the code with [weak self]. It doesn't help. In my limited understanding, the cycle should be broken when
self.anim.removeAllBehaviors();self.mv!.removeFromSuperview()is executed.##Update
With the "Debug Memory Graph" tool in XCode, I saw
UIGravityBehavioris still retained by the animator even afterself.anim.removeAllBehaviors()is called.