在ARC下使用
1 | [theTarget performSelector:theTarget withObject:Nil]; |
会出现警告:performselector-may-cause-a-leak-because-its-selector-is-unknown
解决方法:
1:添加如下宏
1 | #define SuppressPerformSelectorLeakWarning(Stuff) \ |
2 | do { \ |
3 | _Pragma("clang diagnostic push") \ |
4 | _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \ |
5 | Stuff; \ |
6 | _Pragma("clang diagnostic pop") \ |
7 | } while (0) |
2:使用宏
1 | SuppressPerformSelectorLeakWarning([theTarget performSelector:theAction withObject:@"hello"]); |
本文介绍了解决Objective-C ARC环境下使用performSelector方法可能引发内存泄露的问题,通过使用宏SuppressPerformSelectorLeakWarning来避免警告,并提供了解决方案及参考链接。

被折叠的 条评论
为什么被折叠?



