Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码有大问题 #2

Open
tiger8888 opened this issue Dec 19, 2016 · 13 comments
Open

代码有大问题 #2

tiger8888 opened this issue Dec 19, 2016 · 13 comments

Comments

@tiger8888
Copy link

别的不说,
NSInteger retainCount = [[object valueForKey:@"retainCount"] integerValue];
if (retainCount == 2) { // 对象应该被回收了
[[self themeColorPool] removeObject:dict];
}
竟然使用引用计数, 来判断,也是醉了. 为什么不使用weakObjectsHashTable等来存放......

@tiger8888
Copy link
Author

retainCount也就调试时用下,甚至在ARC下,只用instruments来查看引用计数.
http://stackoverflow.com/questions/8863269/how-do-i-verify-reference-count-in-arc-mode

@tiger8888 tiger8888 changed the title 代码有大问题工 代码有大问题 Dec 19, 2016
@ko1o
Copy link
Owner

ko1o commented Dec 19, 2016

@tiger8888 说得是,这点我疏忽了,欢迎根据您的经验 完善一下,pull request me!

@ArmsZhou
Copy link

直接字典存,会导致内存释放失败的吧。

@ko1o
Copy link
Owner

ko1o commented Dec 22, 2016

字典存不会导致释放失败。因为如果对象应该被释放,就会直接删除字典,但是这样不是最合理的,更合理的应该是像楼上说的,采用弱引用

@ArmsZhou
Copy link

ArmsZhou commented Dec 22, 2016 via email

@ko1o
Copy link
Owner

ko1o commented Dec 22, 2016

@ArmsZhou 我知道你说的了, 就是我处理的那个方法,最多会有一个对象不能及时被释放。所以我觉得采用weakObjectsHashTable来存放了,谢谢 @tiger8888 的建议!

@ko1o
Copy link
Owner

ko1o commented Dec 22, 2016

@tiger8888 @ArmsZhou 最后我的解决方案是采取:NSMapTable存储,目前还在测试!预计明天发布,最近比较忙!欢迎到时候测试、反馈!

@ko1o
Copy link
Owner

ko1o commented Dec 23, 2016

@tiger8888 @ArmsZhou 现在已经使用NSMapTable替代NSDictionary存储了,欢迎更新、测试!

@ArmsZhou
Copy link

ArmsZhou commented Jan 4, 2017

// 采用NSMapTable存储对象,使用弱引用
NSMapTable *mapTable = [NSMapTable mapTableWithKeyOptions:NSMapTableCopyIn valueOptions:NSMapTableWeakMemory];
[mapTable setObject:self forKey:pointSelectorString];
[mapTable setObject:objects forKey:PYTHEME_COLOR_ARGS_KEY];

你的第一个[mapTable setObject:self forKey:pointSelectorString];这个是合理的可以防止强引用控件。但是[mapTable setObject:objects forKey:PYTHEME_COLOR_ARGS_KEY];也设置为弱引用的话可能导致设置的参数数组会被释放掉。

@wuyeRoy
Copy link

wuyeRoy commented Jan 6, 2017

Demo中 tabBar的 文字颜色无法改变 ???

@ko1o
Copy link
Owner

ko1o commented Jan 6, 2017

@wuyeRoy 不好意思 demo没处理好!现在修复了 谢谢反馈!

@wuyeRoy
Copy link

wuyeRoy commented Jan 6, 2017

再请教下 如果我不用tabBar 中间的加号按钮 应该怎么写?

@DYS12345
Copy link

如果view的颜色要是红色,上面的label颜色要是黑色,如何改,看Demo里都是一样的颜色,能根据不同控件改不同的颜色吗。

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

No branches or pull requests

5 participants