Git Product home page Git Product logo

Comments (9)

chennyhuang avatar chennyhuang commented on June 26, 2024

截个图看看哪些成员变量导致了警告

from hzphotobrowser.

MrCaiWH avatar MrCaiWH commented on June 26, 2024

image
block里的成员变量都报了,block里写成员变量也是会引起循环引用的,出了问题还不好排查

from hzphotobrowser.

chennyhuang avatar chennyhuang commented on June 26, 2024

xcode版本能否告知?

from hzphotobrowser.

MrCaiWH avatar MrCaiWH commented on June 26, 2024

@chennyhuang 9.4

from hzphotobrowser.

chennyhuang avatar chennyhuang commented on June 26, 2024

理论上UIview的block不会造成循环引用:
首先循环引用发生的条件就是持有这个block的对象,被block里边加入的对象持有。当然是强引用。
所以UIView的动画block不会造成循环引用的原因就是,这是个类方法,当前控制器不可能强引用一个类,所以循环无法形成。
UIView中的block持有当前控制器,但是当前控制器中是没有持有UIView类的,没有形成循环.当动画结束时,UIView会结束持有这个block,如果没有别的对象持有block的话,block对象就会被释放掉,从而block会释放掉对self的持有,整个内存引用关系被解除.

from hzphotobrowser.

chennyhuang avatar chennyhuang commented on June 26, 2024

当 block 本身不被 self 持有,而被别的对象持有,同时不产生循环引用的时候,就不需要使用 weak self 了。最常见的代码就是 UIView 的动画代码,我们在使用 UIView 的 animateWithDuration:animations 方法 做动画的时候,并不需要使用 weak self,因为引用持有关系是:

UIView 的某个负责动画的对象持有了 block
block 持有了 self
因为 self 并不持有 block,所以就没有循环引用产生,因为就不需要使用 weak self 了。

from hzphotobrowser.

MrCaiWH avatar MrCaiWH commented on June 26, 2024

@chennyhuang 谢谢,学到了,请问作者,可以展示本地拿到的UIImage吗

from hzphotobrowser.

chennyhuang avatar chennyhuang commented on June 26, 2024

不支持本地,本地的自己写一个了,太简单

from hzphotobrowser.

agiapp avatar agiapp commented on June 26, 2024

去除Block中实例变量警告的方法:Building Settings ->搜索implicit retain of 'self' ,将对应的值改为NO

from hzphotobrowser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.