仅在设备测试时显示内存泄漏。不知道为什么。?

时间:2012-06-21 11:52:57

标签: iphone objective-c ios xcode memory-leaks

enter image description here

大家好,

在我的iPhone应用程序中,当我在显示这些错误的设备上运行它时。那么请告诉我这些是App拒绝的原因吗?

请告诉我,为什么会出现这些错误?

这是我正在使用的代码。请看一下:

NSMutableString* s = [[[NSMutableString alloc]init]autorelease];
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[s appendFormat: @"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"%@\">", ns];
if(headers != nil && headers.count > 0) {
    [s appendString: @"<soap:Header>"];
    for(id key in [headers allKeys]) {
        if([[headers objectForKey: key] isMemberOfClass: [SoapNil class]]) {
            [s appendFormat: @"<%@ xsi:nil=\"true\"/>", key];
        } else {
            [s appendString:[Soap serializeHeader:headers forKey:key]];
        }
    }
    [s appendString: @"</soap:Header>"];
}
[s appendString: @"<soap:Body>"];
[s appendFormat: @"<%@>%@</%@>", method,[params stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"], method] ;
[s appendString: @"</soap:Body>"];
[s appendString: @"</soap:Envelope>"];
return s;

2 个答案:

答案 0 :(得分:0)

我认为你创建了一个NSMutableString。如果您不使用ARC,则必须将其释放。

答案 1 :(得分:0)

NSMutableString* s = [[[NSMutableString alloc]init]autorelease];
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[s appendFormat: @"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"%@\">", ns];
if(headers != nil && headers.count > 0) {
    [s appendString: @"<soap:Header>"];
    for(id key in [headers allKeys]) {
        if([[headers objectForKey: key] isMemberOfClass: [SoapNil class]]) {
            [s appendFormat: @"<%@ xsi:nil=\"true\"/>", key];
        } else {
            [s appendString:[Soap serializeHeader:headers forKey:key]];
        }
    }
    [s appendString: @"</soap:Header>"];
}
[s appendString: @"<soap:Body>"];
[s appendFormat: @"<%@>%@</%@>", method,[params stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"], method] ;
[s appendString: @"</soap:Body>"];
[s appendString: @"</soap:Envelope>"];
return s;

这是我正在使用的代码。请看一下。