YTKNetwork icon indicating copy to clipboard operation
YTKNetwork copied to clipboard

YTKNetwork是否存在内存泄漏问题?

Open xslonepiece opened this issue 6 years ago • 2 comments

提出问题前请先确认完成了下列几项步骤 New Issue Checklist

  • [ ] 我已经阅读过 贡献指南 I have read and understood the CONTRIBUTING guide
  • [ ] 我已经阅读过 程序文档 I have read the Documentation
  • [ ] 我已经证实这个问题来源于 YTKNetwork 本身,而不是其所依赖的 AFNetworking I have confirmed that this issue is caused by YTKNetwork, not AFNetworking
  • [ ] 我已经在项目的 问题列表 中搜索过并且没有找到类似问题 I have searched for a similar issue in the project and found none

问题描述 Issue Description

请给出所提出问题的详尽描述,包括具体的错误信息,打印的堆栈等等,以及重现此问题的具体步骤。

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

xslonepiece avatar Sep 28 '18 07:09 xslonepiece

用instrument leaks跑一遍,全是AF的内存泄漏。 之前用AF sessionManager用单例未发生过。(网上也搜到解决AF内存泄漏的解决方式就是sessionManager用单例。) 从YTKNetwork源码可看出,每个request都会创建sessionManager去发请求,请问要如何避免内存泄漏?

xslonepiece avatar Sep 28 '18 07:09 xslonepiece

@implementation YTKNetworkAgent {
    AFHTTPSessionManager *_manager;
    YTKNetworkConfig *_config;
    AFJSONResponseSerializer *_jsonResponseSerializer;
    AFXMLParserResponseSerializer *_xmlParserResponseSerialzier;
    NSMutableDictionary<NSNumber *, YTKBaseRequest *> *_requestsRecord;

    dispatch_queue_t _processingQueue;
    pthread_mutex_t _lock;
    NSIndexSet *_allStatusCodes;
}

YTKNetworkAgent 对象持有一个 sessionManager。项目里,agent 是当作单列来用的,应该不存在每次请求都创建一个 sessionManager 一说。

expkzb avatar Aug 07 '19 06:08 expkzb