我已经分析了我的代码,分析器显示我的方法之一是在自动释放的对象上泄漏内存。以下是相关代码的片段:
-(void) fillRSSEntriesDictionaryObject: (NSMutableDictionary *) dictionaryObject withAllRSSEntries: (NSArray *) allRSSEntries forKey: (NSString *) keyForRSSEntriesArchive {
RSSEntry *anRSSEntry;
NSArray *source;
NSMutableArray *episodes;
NSMutableArray *sourceArray = [[[NSMutableArray alloc] initWithObjects:nil] autorelease];
for (int i=0; i<[allRSSEntries count]; i++) {
source = [allRSSEntries objectAtIndex:i]; // grab the next source array.
episodes = [[[NSMutableArray alloc] initWithObjects:nil] autorelease]; // initialize the episodes array
for (int j=0; j<[source count]; j++) {
anRSSEntry = [source objectAtIndex:j];
NSDictionary *episodeDictionary = [NSDictionary dictionaryWithObjectsAndKeys:anRSSEntry.blogTitle, @"Blog Title",
anRSSEntry.articleTitle, @"Article Title", nil];
[episodes addObject:episodeDictionary]; // save the info for this episode
}
[sourceArray addObject:episodes];
}
// Finally, we need to create the key-value pair for the source array
[dictionaryObject setObject:sourceArray forKey: keyForRSSEntriesArchive];
}
如您所见,sourceArray 和 Episodes 是唯一分配的内存,并且两者都是自动释放的。episodes 数组被添加到 sourceArray 数组中。sourceArray 成为传递给调用者的对象。
profiler提供的具体信息是,负责的库是“基础”,负责的调用者是+[NSDictionary(NSDictionary)newWithContentsOf:immutable]。当我扩展它时,它最终将我的应用程序作为负责的库,并将此方法作为负责的调用者。
既然这些是自动释放的数组,为什么分析器会抱怨内存泄漏?