I added a progress bar on my application. everything is fine, running the way I want them. but the problem is when I append the downloaded data in didReceivedData: , my responseData is getting reallocated and thus makes my application consume too much memory. then crash after receivedMemoryWarning.
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//response data is getting reallocated with bigger size of data
[responseData appendData:data];
NSNumber* curLength = [NSNumber numberWithLong:[responseData length] ];
float progress = [curLength floatValue] / [filesize floatValue] ;
progressView.progress = progress;
}
Can someone here help me how to get rid of reallocation in my responseData?
thanks!!!
When creating
responseData, useinitWithCapacity:to give it a hint how many bytes you will require (the expected content length can possibly be retrieved from the response header).