Skip to content

fix:Retain Cycle by NSTimer#23

Open
zox01 wants to merge 1 commit intodsxNiubility:masterfrom
zox01:master
Open

fix:Retain Cycle by NSTimer#23
zox01 wants to merge 1 commit intodsxNiubility:masterfrom
zox01:master

Conversation

@zox01
Copy link

@zox01 zox01 commented Aug 22, 2019

NSTimer 在使用时要比较小心,当设置重复触发,NSTimer对象会强引用注册时的target,如果target本身又持有NSTimer对象,就造成了循环引用,可以通过引入中间对象通过弱引用持有接受回调的对象,然后以这个中间对象注册NSTimer对象,再在中间对象内部把消息转发给实际需要接受NSTimer回调消息的对象。具体可以参考Weak Reference to NSTimer Target To Prevent Retain Cycle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant