I have tried to find answers online and I did find a few relevant answers on SO, but I really want to confirm I understand it correctly (which maybe I don't)
I have this code:
- (NSArray*)arrayMethod
{
MPMediaQuery *albumArtistsQuery = [MPMediaQuery artistsQuery];
[albumArtistsQuery setGroupingType:MPMediaGroupingAlbumArtist];
return @[
@[ kTypeArtists, NSLocalizedString(@"Artists", nil), albumArtistsQuery, @"skin:iconArtists" ],
@[ kTypeAlbums, NSLocalizedString(@"Albums", nil), [MPMediaQuery albumsQuery], @"skin:iconAlbums" ],
@[ kTypeTracks, NSLocalizedString(@"Tracks", nil), [MPMediaQuery songsQuery], @"skin:iconSongs" ],
@[ kTypeComposers, NSLocalizedString(@"Composers", nil), [MPMediaQuery composersQuery], @"skin:iconComposers" ],
@[ kTypeGenres, NSLocalizedString(@"Genres", nil), [MPMediaQuery genresQuery], @"skin:iconGenres" ],
@[ kTypePlaylists, NSLocalizedString(@"Playlists", nil), [MPMediaQuery playlistsQuery], @"skin:iconPlaylists" ],
@[ kTypePodcasts, NSLocalizedString(@"Podcasts", nil), [MPMediaQuery podcastsQuery], @"skin:iconPodcasts" ],
];
}
- (void)someMethod
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
for (NSArray* current in [self arrayMethod]) {
[dict setObject:current forKey:current[0]];
}
self.rootDict = [NSDictionary dictionaryWithDictionary:dict];
}
kTypeArtists etc are just static const NSString*
When I use profiling instruments (more specifically leak instrument) in xcode, I get a memory leak of the returned NSArray and the responsible frame is the method arrayMethod
From what I've read my understanding is, that this is not a memory leak, but when inside someMethod
I'm passing the NSArray to otherMethod
as an argument, retain count is increased for the array and will be released some time later in the future when autorelease pool drains, but this can happen later in runtime, so it's not really a memory leak, just the leak instrument shows it as such;
But I'm also skeptical, that the tool would be showing it as memory leak, then it would be quite useless tool; So maybe my understanding is not correct and I actually do have a memory leak, but I just can't understand why.
Can anybody explain if I'm right or wrong and why? Thanks!
EDIT:
I have also tried to change the code to [[self arrayMethod] copy]
but didn't help;