NSBundle 分类中 mj_arrowImage 有内存泄漏?
webMing opened this issue · comments
重现步骤
-
新建一个工程; 下载tag为3.7.5的版本并拖入工程.
-
工程配置: Target -> build setting -> debug information format -> debug -> DWARF with dSYM file
配置目的:可以在debug模式下找可能有内存泄漏的代码 -
在第一个启动的VC的 ViewDidLoad中 放入如下代码
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRereshing)];
- 手机运行该工程;
- 打开instruments -> leaks工具 ; 设备 设置为手机; 项目配置为 该工程
- 点击leaks中的recording 开始进行检查 在线面leaks 详细介绍中会发现 leakedObject: NSPathStore2
- 利用 call tree 定位发现问题在下面的代码中
+ (instancetype)mj_refreshBundle
{
static NSBundle *refreshBundle = nil;
if (refreshBundle == nil) {
#ifdef SWIFT_PACKAGE
NSBundle *containnerBundle = SWIFTPM_MODULE_BUNDLE;
#else
NSBundle *containnerBundle = [NSBundle bundleForClass:[MJRefreshComponent class]];
#endif
refreshBundle = [NSBundle bundleWithPath:[containnerBundle pathForResource:@"MJRefresh" ofType:@"bundle"]];
}
return refreshBundle;
}
+ (UIImage *)mj_arrowImage
{
static UIImage *arrowImage = nil;
if (arrowImage == nil) {
// 这里如果换成NSbunddle.mainBundle 是没有问题.
// NSString* path = [[NSBundle mainBundle] pathForResource:@"arrow@2x" ofType:@"png"];
// UIImage* arrow = [[UIImage imageWithContentsOfFile:path] //imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
return arrowImage;
}
环境
Xcode Version 13.1 (13A1030d)
iPhone XS Max 13.7
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
可否上传一个 Demo 工程. 我这边测试没有溢出问题...是不是配置问题, 我使用的是库中的 Demo
我也遇到了这个问题,xcode版本为Version 13.4.1 (13F100),使用instrument采集内存之后,确实有内存泄漏.
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
您好,邮件已收到。