私は統計モニターアプリケーションを構築しています。私はデータパーサーを使用してXMLパーサーを検索しています。 obj-cのメモリ管理とretainCountなどについて多くの研究、学習、読解が行われたが、引き続きInstrumentsでメモリリークが発生する。メモリー管理リークを修正する方法
for(int counter = 0; counter < [resultElement childCount]; counter++) { //Loop trough the childs
//Instruments Leaks tells me that I have 75% leaks here
[entryItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
}
//Instruments Leaks tells me that I have 25% leaks here
[totalEntries addObject:[entryItem copy]]; //Copy it into the MutableArray
XMLパーサーでメモリリークが発生しましたが、リークを修正する方法がわかりません。ラインで
- (NSString *)stringValue {
if (_node->type == XML_TEXT_NODE || _node->type == XML_CDATA_SECTION_NODE){
return [NSString stringWithUTF8String:(const char *)_node->content]; //16.7% leaking
}
if (_node->type == XML_ATTRIBUTE_NODE){
return [NSString stringWithUTF8String:(const char *)_node->children->content]; //50.0% leaking
}
NSMutableString *theStringValue = [[[NSMutableString alloc] init] autorelease];
for (CXMLNode *child in [self children]) {
[theStringValue appendString:[child stringValue]]; //33.3% leaking
}
return theStringValue;
}
非常に良いと明確な説明! –
私はすでにaddObject関数の下でentryItemを公開しているので、私の例では間違いを犯しました。問題は実際に私が投稿した2番目の例にあるように発生します。 – Leon
はカスタムオブジェクトまたはコレクションのtotalEntriesですか? – jbat100