As the users test my app, he random click the screen very quickly, like a monkey , to into my every detail view controller
, because every into my detail vc
, the vc
will fetch data
from the net. And in the real device my app crash
.
I think this issue is cause by memory leak
, because this did not appear in simulator
, I test my app in instrument
, the screenshoot
in below:
In instrument:
The situation:
my main screen, click the every
item
on the main screen will in to a different detailvc
.detail one
vc
, every in detailvc
, user test willfetch data
or click random:the memory grow to
90.5MB
, and did not come down, if use user's test method, if take more long time, will be more than90.5MB
:
I use instrument
is not that well, and the memory is most used by AFNetworking
, i don't know how to do with this. Someone can give advice? Most thanks in advance.
EDIT
I make the AFHTTPSessionManager
to be a singleton
, but I found my net request become slowly, does this affect me?
#import "Mysevers.h"
#import "AFNetworking.h"
#import "HUD.h"
static AFHTTPSessionManager *requestManager ;
@implementation Mysevers
+ (AFHTTPSessionManager *)sharedHTTPSession{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
requestManager = [AFHTTPSessionManager manager];
requestManager.requestSerializer.timeoutInterval = 10;
});
return requestManager;
}
+(void)AFPOSTWithHud:(BOOL)hud andAddressname:(NSString*)addressName parmas:(NSDictionary*)parmas RequestSuccess:(void(^)(id result))success failBlcok:(void(^)(void))failBlcok
{
if (hud) {
//[HUD addHUD];
[SVProgressHUD show];
}
AFHTTPSessionManager *requestManager = [Mysevers sharedHTTPSession];
NSString *urlStr = [NSString stringWithFormat:@"%@%@",BASE_URL,addressName];
DLog(@"%@",urlStr);
[requestManager POST:urlStr parameters:parmas progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (hud) {
//[HUD removeHUD];
[SVProgressHUD dismiss];
}
success(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (error != nil) {
DLog(@"error==%@",[error localizedDescription]);
if (hud) {
//[HUD removeHUD];
[SVProgressHUD dismiss];
}
failBlcok();
}
return ;
}];
}
+(void)AFGETWithHud:(BOOL)hud andAddressname:(NSString*)addressName parmas:(NSDictionary*)parmas RequestSuccess:(void(^)(id result))success failBlcok:( void(^)(void))failBlcok
{
if (hud) {
//[HUD addHUD];
[SVProgressHUD show];
}
AFHTTPSessionManager *requestManager = [Mysevers sharedHTTPSession];
NSString *urlStr = [NSString stringWithFormat:@"%@%@",BASE_URL,addressName];
DLog(@"%@",urlStr);
[requestManager GET:urlStr parameters:parmas progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (hud) {
//[HUD removeHUD];
[SVProgressHUD dismiss];
}
success(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
DLog(@"error==%@",[error localizedDescription]);
if (hud) {
//[HUD removeHUD];
[SVProgressHUD dismiss];
}
failBlcok();
}];
}
@end