ios - Leak when downloading with AFNetworking -
basically when file done downloading, there's "something" in memory never gets released. here's simplistic example of code causing problem, memory goes around 50mb , sits there , never gets released (see screenshots below). idea of what's going on?
-(void)download { nsstring* urlstring = @"http://download.thinkbroadband.com/50mb.zip"; nsmutableurlrequest* request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:urlstring]]; afhttprequestoperation* operation = [[afhttprequestoperation alloc] initwithrequest:request]; [operation setdownloadprogressblock:^(nsuinteger bytesread, long long totalbytesread, long long totalbytesexpectedtoread) { nslog(@"%lldmb of %lldmb downloaded", totalbytesread / 1024 / 1024, totalbytesexpectedtoread / 1024 / 1024); }]; [operation setcompletionblockwithsuccess:^(__weak afhttprequestoperation *operation, id responseobject) { nslog(@"download completed."); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", error.localizeddescription); }]; [operation start]; }
before download:
after download:
in own testing on ios 8.1 using afnetworking 2.5, appears case in debug not release mode. given code didn't work is, made following test case:
- (ibaction)startdownload:(uibutton *)sender { nsstring *downloadurlstring = @"http://mirror.internode.on.net/pub/test/50meg.test"; nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:downloadurlstring]]; afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; manager.responseserializer = [afhttpresponseserializer serializer]; afhttprequestoperation *operation = [manager httprequestoperationwithrequest:request success:^(afhttprequestoperation *operation, id responseobject) { nslog(@"download succeeded."); self.statelabel.text = @"download succeeded."; } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"download failed error: %@", error); self.statelabel.text = @"download failed."; }]; [operation setdownloadprogressblock:^(nsuinteger bytesread, long long totalbytesread, long long totalbytesexpectedtoread) { nslog(@"bytes read: %lu", bytesread); nslog(@"total bytes read %lld", totalbytesread); nslog(@"total progress: %lf", (long double)totalbytesread / totalbytesexpectedtoread); self.progressview.progress = (long double)totalbytesread / totalbytesexpectedtoread; }]; nslog(@"starting download."); nsoperationqueue *downloadqueue = [[nsoperationqueue alloc] init]; [downloadqueue addoperation:operation]; }
with code, once download complete, in release mode, memory usage drops pre download level.
Comments
Post a Comment