my app crashed after received memory warning while uploading data

Each time I will upload a slice of data about 2Mb by calling the following method.

After called about 30 times, the app will received memory warning, then after about 20 times more, the app will just crash without any information.Is there anything wrong in my code? I didn't find any memory leaks in my code.

//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];
}

Answers


You're queueing too many requests at one time - ASIHTTPRequest will keep your data in memory until it's sent to the server, so it's not surprising that you run out of memory.

Try making sure you don't have more than 3 or 4 requests outstanding in the queue - ie. queue 4 to start with, then queue another one when one finished, and so on.


Need Your Help

How To Use ElasticSearch In Vertx Java With EventBus?

java elasticsearch vert.x

Can Somebody let me know how to use elasticsearch in vertx for java.I have used eventbus but i couldn't able to get it done. New to Vertx. Any help will be appreciated.