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

NSBundle 分类中 mj_arrowImage 有内存泄漏? #1563

Open
webMing opened this issue Jan 4, 2022 · 9 comments
Open

NSBundle 分类中 mj_arrowImage 有内存泄漏? #1563

webMing opened this issue Jan 4, 2022 · 9 comments
Labels
detail-Need(Demo) 需要更多信息

Comments

@webMing
Copy link

webMing commented Jan 4, 2022

重现步骤

  • 新建一个工程; 下载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

@webMing webMing added the bug label Jan 4, 2022
@309598016

This comment was marked as off-topic.

@webMing webMing changed the title NSBundle mj_arrowImage 内存泄漏 NSBundle 分类中 mj_arrowImage 有内存泄漏? Jan 4, 2022
@wolfcon
Copy link
Collaborator

wolfcon commented Jan 5, 2022

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

@webMing
Copy link
Author

webMing commented Jan 5, 2022

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

@wolfcon wolfcon added detail-Need(Demo) 需要更多信息 and removed bug labels Jan 5, 2022
@wolfcon
Copy link
Collaborator

wolfcon commented Jan 5, 2022

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

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

@webMing
Copy link
Author

webMing commented Jan 5, 2022

@wolfcon https://gitee.com/stephanieer/tmj.git 里面还有图片

@wolfcon
Copy link
Collaborator

wolfcon commented Feb 17, 2022

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

@luoboding
Copy link

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

@309598016
Copy link

309598016 commented Mar 21, 2023 via email

@gitph101
Copy link

gitph101 commented Mar 21, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detail-Need(Demo) 需要更多信息
Projects
None yet
Development

No branches or pull requests

5 participants