0

私はiPhone開発に不慣れです。私の質問はメモリ管理ですここに私のコードがあります:

- (void)asynchronousRequestServerWithXMLPost:(NSString *)urlAddress PostData:(NSString *)postContent {

urlAddress = [self encodeStringForURL:urlAddress];
theRequest = [[[NSMutableURLRequest alloc] init]autorelease];
[theRequest setURL:[NSURL URLWithString:urlAddress]];
if([postContent length] > 0) {
    [theRequest setHTTPMethod:@"POST"];
} else {
    [theRequest setHTTPMethod:@"GET"];
}



NSData *theBodyData = [postContent dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
[theRequest setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSString *postLength = [NSString stringWithFormat:@"%d", [theBodyData length]];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:theBodyData];    

[NSThread detachNewThreadSelector:@selector(sendSyncRequest) toTarget:self withObject:nil];

}

私はこれらの行でリークを取得しています:

theRequest = [[[NSMutableURLRequest alloc] init]autorelease];
[theRequest setURL:[NSURL URLWithString:urlAddress]];
NSData *theBodyData = [postContent dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
[theRequest setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];

誰かが助けてくれるなら、私を助けてください。ありがとうございます。

4

1 に答える 1

0

私はあなたのリークがこの行によって作成されていると推測しています:

urlAddress = [self encodeStringForURL:urlAddress];

encodeStringForURLのコードを確認する必要がありますが、自動リリースせずにコードを返す場合は推測します。また、そのメソッドの結果をパラメーター変数に割り当てないため、参照が失われます。代わりに、次のようなことを行う必要があります。

NSString *encodedUrlAddress = [self encodeStringForURL:urlAddress];

次に、URLWithStringを呼び出すときにencodedUrlAddressを使用します。

于 2012-05-22T06:11:33.867 に答える