Today I was free and checked for a memory leak in the project using the Leaks tool in Xcode’s Instruments. – Happy to check the MMP, the first is green, the others are ❌, cheated. These ❌ are memory leaks. OK, start from the beginning. I think you’re familiar with this tool. How to use it? I found that callTree is basically reported by Af memory leak, read a lot of information in the network. Look at the source code, it turns out that we will call every network request:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer];

The interface was not released after the request was completed. Finally, I made the object AFHTTPSessionManager singleton, that is, I use a manager every time I request the interface. After the debugging is OK, the previous ❌ is missing. Still have the effect, below the singleton to create the code paste, record.

#import "JYJHTTPTool.h"static AFHTTPSessionManager *manager; +(AFURLSessionManager *)sharedManager { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ manager = [AFHTTPSessionManager manager]; manager.requestSerializer = [AFHTTPRequestSerializer serializer]; / / cache strategy manager. RequestSerializer. CachePolicy = NSURLRequestReloadIgnoringLocalCacheData; / / set the timeout [manager requestSerializer willChangeValueForKey: @"timeoutInterval"];
        manager.requestSerializer.timeoutInterval = 30.f;
        [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"]; / / 4. Set the response data type [manager. ResponseSerializersetAcceptableContentTypes:[NSSet setWithObjects:@"application/json"The @"text/json"The @"text/javascript"The @"text/html"The @"text/css"The @"text/plain"The @"application/javascript"The @"image/jpeg"The @"text/vnd.wap.wml"The @"application/x-javascript"The @"image/png", nil]];
        [manager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
    });
    return manager;
    
}
Copy the code

AFHTTPSessionManager * Manager = [AFHTTPSessionManager manager]; AFHTTPSessionManager *manager = [JYJHTTPTool sharedManager]; OK! ❌ didn’t. Have a problem can everybody discuss together!