Reputation: 3880
I have profiled my code and the profiler shows that one of my methods is leaking memory on objects that are autoreleased. Here is a snippet of the relevant code:
-(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];
}
As you can see, sourceArray and episodes are the only alloc'd memory and both are autoreleased. The episodes array is added to the sourceArray array. The sourceArray becomes the object that is passed to the caller.
The specific information provided by the profiler is that the responsible library is "foundation" and the responsible caller is +[NSDictionary (NSDictionary) newWithContentsOf:immutable]. When I expand this, it eventually points to my app as the responsible library and this method as the responsible caller.
Since these are autoreleased arrays, why is the profiler complaining about leaked memory?
Upvotes: 2
Views: 529
Reputation: 8012
There's no leak here. Most likely some other code later uses these objects and leaks them.
You can use Instruments to see the retain/release history of the leaked objects, which should help you find the extra retain or missing release.
Upvotes: 1