Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

楼主,你的这个框架会内存泄露啊 #3

Closed
xeroCBW opened this issue Aug 4, 2016 · 11 comments
Closed

楼主,你的这个框架会内存泄露啊 #3

xeroCBW opened this issue Aug 4, 2016 · 11 comments

Comments

@xeroCBW
Copy link

xeroCBW commented Aug 4, 2016

我在一个 navigationController 放 JHUD,当我 pop 回去的时候,就发现内存泄露了

2016-08-04 23:18:38.458 CBWEmptyViewDemo[913:20546] Memory Leak: (
TestViewController,
UIView,
JHUD
)

@Jinxiansen
Copy link
Owner

你好,可否提供这个Demo与我了解一下。

@xeroCBW
Copy link
Author

xeroCBW commented Aug 5, 2016

你在第二个 item 进去-->next-->touch一下-->马上 pop 回去,就会看到内存泄露的弹框
CBWEmptyViewDemo副本.zip

@Jinxiansen
Copy link
Owner

我看了下,定时器在没有调用hide方法就返回而导致,应该是类方法中的objc函数可能导致,
暂时没有更好的办法,建议使用实例方法。😂

@xeroCBW
Copy link
Author

xeroCBW commented Aug 5, 2016

其实这个是objc_setAssociatedObject的OBJC_ASSOCIATION_RETAIN_NONATOMIC导致的,但是您的换成OBJC_ASSOCIATION_ASSIGN会崩溃

@Jinxiansen
Copy link
Owner

Yeah ,这个我有测试过,所以现在迫于所学有限,不好下手啊。😂

@xeroCBW
Copy link
Author

xeroCBW commented Aug 5, 2016

根据WWDC 2011, Session 322 (第36分钟左右)发布的内存销毁时间表,被关联的对象在生命周期内要比对象本身释放的晚很多。它们会在被 NSObject -dealloc 调用的 object_dispose() 方法中释放。

看下这个
http://nshipster.cn/associated-objects/

@Jinxiansen
Copy link
Owner

🙂 好。
道友可以先尝试JHUD.m中注掉 的 hideForView:(UIView *)view 方法来隐藏。

@Jinxiansen
Copy link
Owner

如上所言,我参考了MBProgressHUD,移除了OBJC相关方法,使用+hideForView:(UIView *)view来实现隐藏的目的。
已更新JHUD。

@ZenonHuang
Copy link

@xeroxmx 学习了一波,兄弟能提供下内存泄露的一些解决方法吗?目前使用MLeaksFinder,有时就算知道哪里出了问题,也有些无从下手的感觉,不知道如何修改

@xeroCBW
Copy link
Author

xeroCBW commented Aug 10, 2016

@zzgo 也苦恼于内存泄露的代码在哪里, MLeaksFinder只会显示类,不会显示具体的哪一些代码内存,上次遇到 SEL 作为属性用 strong,结果内存泄漏了,找了半天才找到,要用 weak

@Jinxiansen
Copy link
Owner

😂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants