しかし、この問題について質問されている質問はたくさんありますが、それらを読んでメソッドを試しても、私のアプリはまだメモリをリークしているようです。私はApple Guide on Memory Manegmentを学び、注目すべき質問here,hereおよびhereを読みました。私は、JSON文字列を解析し、それらをNSMutableDictionary
に返すメソッドを持っています。返すメソッドのオブジェクトに対してautorelease
を呼び出し、受信メソッドでretain
を呼び出します(オブジェクトがプールの次のドレインでdeallocされないことを保証します)。その後、私はそれを完了したときにオブジェクトを解放します。しかしそれはまだ漏れている。誰でも私が間違っていることを見ることができますか?Objective C自動リリースオブジェクトのメモリがリークする
戻るメソッドクラス
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
//This class will take the responsibility of the object's ownership
self.jsonArray = [[SpecialtyUrl parseSpecialtyResult:responseString] retain];
[tableView reloadData];
[responseString release];
}
- (void)dealloc
{
[super dealloc];
//No longer need the object
[jsonArray release];
NSLog(@"Ref count %i", [jsonArray retainCount]);
}
ログを呼び出す
+ (NSMutableArray *)parseSpecialtyResult:(NSString *)json
{
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *dictionary = [parser objectWithString:json];
NSArray *jsonObjects = [dictionary valueForKey:@"Rows"];
NSMutableArray *jsonArray = [[NSMutableArray alloc] initWithCapacity:[jsonObjects count]];
//Storing objects
for (NSDictionary *dict in jsonObjects)
{
Specialty *specialty = [[Specialty alloc] init];
[specialty setName:[dict objectForKey:@"name"]];
[specialty setIdenity:[dict objectForKey:@"id"]];
[jsonArray addObject:specialty];
}
[parser release];
//Relinquish ownership of this object
return [jsonArray autorelease];
}
Ref count 1
また、retainCountはこの種のものを見るのにかなり役に立たない方法です。ここでそれを検索すれば、それについてのbbumの話が頻繁に見られます。 (彼はAppleのどこで働いているのか知っておくべきです) –
通常はretainCountは実際の情報を表示しません。あなたがチェックしたいのであれば、楽器を使ってメモリが増えていますか? Btwすることができます1)特殊なリリース、これはリークを作ることができます。 – Alex
@Grant情報に感謝します。私はプロファイラでダブルチェックして、それが漏れていることを確認しました:( –