Created
January 27, 2014 07:09
-
-
Save ivan3bx/79e8e712493d3d41a42a to your computer and use it in GitHub Desktop.
Forced to use @autoreleasepool in order to avoid memory leak in MPMediaItemArtwork.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableArray *albumIDs = [[NSMutableArray alloc] initWithCapacity:1000]; | |
for (MPMediaItemCollection *collection in items) { | |
@autoreleasepool { | |
MPMediaItem *props = collection.representativeItem; | |
NSString *albumTitle = [props valueForProperty:MPMediaItemPropertyAlbumTitle]; | |
NSString *artistName = [props valueForProperty:MPMediaItemPropertyAlbumArtist]; | |
MPMediaItemArtwork *artwork = [props valueForProperty:MPMediaItemPropertyArtwork]; | |
if (CGSizeEqualToSize(CGSizeZero, artwork.bounds.size)) { | |
// NSLog(@"Album doesn't have artwork: %@, %@", artistName, albumTitle); | |
} else { | |
// | |
// It counts | |
// | |
[albumIDs addObject:[props valueForProperty:MPMediaItemPropertyAlbumPersistentID]]; | |
} | |
} | |
} | |
NSLog(@"Filtered original set of %li to actual count: %li", (unsigned long)items.count, (unsigned long)albumIDs.count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you remember if the memory leak in getting the MPMediaItemArtwork or in using imageWithSize: on that artwork elsewhere?