CoderMJLee / MJRefresh

An easy way to use pull-to-refresh.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

commented

可否上传一个 Demo 工程. 我这边测试没有溢出问题...是不是配置问题, 我使用的是库中的 Demo

@wolfcon 直接拉取 3.7.5 的代码到工程中; 按照操作步骤应该可以看到.

commented

@wolfcon 直接拉取 3.7.5 的代码到工程中; 按照操作步骤应该可以看到.

在真机+模拟器都没有复现, 你还是写个 Demo 工程吧.🧐

commented

使用你的工程后, 并没有复现.
你可以在同事或者朋友那边试试看?
image

commented

我也遇到了这个问题,xcode版本为Version 13.4.1 (13F100),使用instrument采集内存之后,确实有内存泄漏.