Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Created January 27, 2014 07:09
Show Gist options
  • Save ivan3bx/79e8e712493d3d41a42a to your computer and use it in GitHub Desktop.
Save ivan3bx/79e8e712493d3d41a42a to your computer and use it in GitHub Desktop.
Forced to use @autoreleasepool in order to avoid memory leak in MPMediaItemArtwork.
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);
@edwinfinch
Copy link

Do you remember if the memory leak in getting the MPMediaItemArtwork or in using imageWithSize: on that artwork elsewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment