【问题标题】:Leak with HttpRequest Method - Objective-c使用 HttpRequest 方法泄漏 - Objective-c
【发布时间】:2013-09-26 09:42:39
【问题描述】:

我是 Analyze 我的应用程序来搜索任何泄漏,这里我们遇到了“存储到 replyString 中的对象的潜在泄漏”。 我尝试了每个版本,但没有任何变化,所以我在这里寻求帮助。

我在我的 WebService 类中创建了这个方法。

-(NSString *)httpRequest{

NSData *postData = [self dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:adresse]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *replyString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding: NSASCIIStringEncoding];
return replyString;
}

谢谢:)

【问题讨论】:

    标签: iphone ios objective-c xcode httprequest


    【解决方案1】:

    您正在使用alloc init 创建replyString,这意味着需要释放replyString,因此:

    return [replyString autorelease];
    

    【讨论】:

    • 我之前试过这个,我的应用程序崩溃了,但它现在似乎可以工作了,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    • 2023-04-06
    • 2011-06-07
    相关资源
    最近更新 更多