Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSConnection sendSynchronousRequest中的内存问题_Ios_Memory_Httpclient_Nsconnection - Fatal编程技术网

Ios NSConnection sendSynchronousRequest中的内存问题

Ios NSConnection sendSynchronousRequest中的内存问题,ios,memory,httpclient,nsconnection,Ios,Memory,Httpclient,Nsconnection,我正在尝试在我的一个iOS项目中使用LolayHttpClient。它工作得很好,除了一个问题-内存不断增长,即使我在autoreleasepool下运行代码 相关代码非常简单。LolayHttpClient使用NSConnection sendSynchronousRequest。因此,我怀疑内存问题是在执行sendSynchronousRequest时造成的。下面是我的测试函数。有人帮忙吗 int main(int argc, char * argv[]) { int m

我正在尝试在我的一个iOS项目中使用LolayHttpClient。它工作得很好,除了一个问题-内存不断增长,即使我在autoreleasepool下运行代码

相关代码非常简单。LolayHttpClient使用NSConnection sendSynchronousRequest。因此,我怀疑内存问题是在执行sendSynchronousRequest时造成的。下面是我的测试函数。有人帮忙吗

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]));

}
ExecuteSynchronousLyatur:url最终在同一线程中同步调用ExecuteMethods,如下所示

- (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;
}
Xcode仪器工具指向以下功能:

HTTPNetStreamInfo::\u readStreamClientCallBack\u CFReadStream*,无符号长


定期调用,每次调用时分配132k字节。

找到解决方案了吗?是的。这不是一个软件错误。我对Xcode instrument tool的理解是错误的——我检查的数字是总内存使用量,包括已释放的内存。