每次我都会通过调用下面的方法上传一段2Mb左右的数据。
调用大约 30 次后,应用程序将收到内存警告,然后大约 20 次后,应用程序将崩溃而没有任何信息。我的代码有什么问题吗?我没有在我的代码中发现任何内存泄漏。
//connect to uploading server, upload one slice of data, and get the next slice uploading point.
-(void)uploadSlice
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *baseUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gupload/upload_slice",_uploadServerIP]];
NSData *sliceData = nil;
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:item.filePath];
if (file == nil)
NSLog(@"Failed to open file");
[file seekToFileOffset:_offset];
sliceData = [file readDataOfLength:_length];
[file closeFile];
NSMutableData *data = [NSMutableData dataWithData:sliceData];
NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:
_uploadToken, @"upload_token",
[NSString stringWithFormat:@"%d",_sliceTaskId],@"slice_task_id",
[NSString stringWithFormat:@"%lld",_offset], @"offset",
[NSString stringWithFormat:@"%d",_length], @"length",
nil];
NSURL *finalUrl = [self generateURL:[baseUrl absoluteString] params:dic];
NSLog(@"upload slice url = %@",finalUrl);
ASIFormDataRequest *aRequest = [ASIFormDataRequest requestWithURL:finalUrl];
[aRequest setPostBody:data];
aRequest.requestMethod = @"POST";
[self setPostUserInfo:aRequest withRequestType:kYoukuUploadSlice];
[_networkQueue addOperation:aRequest];
[dic release];
[pool drain];
}