search

Home  >  Q&A  >  body text

objective-c - block内存管理的问题

[UIView animateWithDuration:0.2 animations:^{
    self.movingView.transform = CGAffineTransformMakeTranslation(200, 0);
}];

非常常用的一个动画block.

那么,在动画 block 中使用了成员变量,会导致 retain cycle 吗?

PHP中文网PHP中文网2766 days ago742

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-04-24 16:02:38

    The so-called "reference cycle" refers to two-way strong references, so those "one-way strong references" (block strong reference self) are no problem

    It is recommended to read the following link, question 39, which is very detailed
    "Recruiting a reliable iOS" interview question reference answer

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-04-24 16:02:38

    If it’s arc it won’t

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-04-24 16:02:38

    If it is arc, then this problem will occur ~ mrc will not.

    Because the member variable you use looks like this to the compiler: self->member. Therefore, in arc mode, although only member variables are used, self actually points to this variable, and there is still a memory leak problem.

    reply
    0
  • Cancelreply