0

i am trying to use LolayHttpClient in one of my iOS project. it works well except one issue - the memory keeps growing even i run the code under autoreleasepool.

The related code is quite straight forward. LolayHttpClient use NSConnection sendSynchronousRequest. So I doubt the memory issue is caused on execution of sendSynchronousRequest. Following is my testing function. would somebody help?

int main(int argc, char * argv[]) {


        int max = 100000;
        while (max > 0) {

        @autoreleasepool {

            [NSURLCache setSharedURLCache:[[NSURLCache alloc] initWithMemoryCapacity:0
                                                                         diskCapacity:0
                                                                             diskPath:nil]];

            GetMethod *get = [[GetMethod alloc] init];
            NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:@"192.168.0.107:10000" path:@"/services"];

            HttpResponse *resp = [get executeSynchronouslyAtURL:url];



            max = max -1;
            NSLog(@"%@", [resp responseString]);
            NSLog(@"%@", [NSString stringWithFormat:@"%d",max]);
            [[NSURLCache sharedURLCache] removeAllCachedResponses];

            [NSThread sleepForTimeInterval:1];
        }

        }

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

}

executeSynchronouslyAtURL:url eventually calls executeMethodSynchronously as follows in the same thread.

- (HttpResponse*)executeMethodSynchronously:(NSURL*)methodURL methodType:(NSString*)methodType dataInBody:(bool)dataInBody contentType:(NSString*)contentType error:(NSError**) error {

    //Create a new URL request object
    NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init];

    if(cachePolicy != NSURLRequestUseProtocolCachePolicy) {
        [request setCachePolicy:cachePolicy];
    }

    [request setHTTPShouldHandleCookies: handleCookies];

    [self prepareMethod:methodURL methodType:methodType dataInBody:dataInBody contentType:contentType withRequest:request];

    NSString* requestBody = [self bodyString];
    DLog(@"Request url=%@, headers=%@, parameters=%@, body=%@", [request URL], [self headers], [self parameters], requestBody.length < 4096 ? requestBody : [NSString stringWithFormat:@"(length=%lu)", (unsigned long) requestBody.length]);

    //Execute the HTTP method, saving the return data
    NSHTTPURLResponse * response;
    NSError* errorResponse = nil;
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&errorResponse];
    HttpResponse * responseObject = [[HttpResponse alloc] initWithHttpURLResponse:response withData:returnData];

    if (errorResponse) {
        DLog(@"Error url=%@, error=%@", [request URL], errorResponse);
        if (error != NULL) {
            *error = errorResponse;
        }
    }

    DLog(@"Response url=%@, status=%li, headers=%@, body=%@", [request URL], (long) [responseObject statusCode], [responseObject headerFields], [responseObject responseString]);

    return responseObject;
}

The Xcode instrument tool points to function:

HTTPNetStreamInfo::_readStreamClientCallBack(__CFReadStream*, unsigned long)

which is called periodically and allocates 132k bytes each time being called.

Jack
  • 21
  • 5
  • Did you find the solution for the same? – Kumar Aditya May 30 '15 at 04:19
  • Yes. it turns out not a software bug. i had wrong understanding for Xcode instrument tool - the number i check is the total memory usage including those had been deallocated. – Jack Aug 05 '15 at 09:29

0 Answers0