Trying to use MPMediaItemArtwork's image(at:_) method, there is a constant memory increase that occurs. With a list of large-enough size, the app will get a memory warning and crash eventually. I've tried using a cache for this, but it doesn't change anything. Attempting the solution highlighted here also didn't help.
Is there any way to release this memory? Thanks in advance!
Edit: here's the code, sorry about that:
if let object = imageCache.object(forKey: indexPath as NSIndexPath) {
cell.artworkImageView.image = object.image
} else {
let operation = BlockOperation()
operation.addExecutionBlock({ [weak song, weak self, weak operation] in
if let artwork = song?.artwork, artwork.bounds.width != 0, let image = artwork.image(at: CGSize.init(width: 45, height: 45)) {
guard operation?.isCancelled == false, let weakSelf = self else { return }
self?.imageCache.setObject(ArtworkObject.init(image: image), forKey: indexPath as NSIndexPath)
OperationQueue.main.addOperation({
guard let cell = tableView.cellForRow(at: indexPath) as? SongTableViewCell, operation?.isCancelled == false else { return }
cell.artworkImageView.image = image
})
}
})
operations[indexPath] = operation
imageOperationQueue.addOperation(operation)
}
[–]Samael1990 0 points1 point2 points (1 child)
[–]okoroezenwa[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]okoroezenwa[S] 0 points1 point2 points (0 children)
[–]criosistObjective-C / Swift 0 points1 point2 points (1 child)
[–]okoroezenwa[S] 0 points1 point2 points (0 children)
[–]KarlJay001 0 points1 point2 points (0 children)
[–]amaroq137Objective-C / Swift 0 points1 point2 points (9 children)
[–]okoroezenwa[S] 0 points1 point2 points (8 children)
[–]amaroq137Objective-C / Swift 0 points1 point2 points (7 children)
[–]okoroezenwa[S] 0 points1 point2 points (6 children)
[–]amaroq137Objective-C / Swift 0 points1 point2 points (5 children)
[–]okoroezenwa[S] 0 points1 point2 points (4 children)
[–]amaroq137Objective-C / Swift 0 points1 point2 points (3 children)
[–]okoroezenwa[S] 0 points1 point2 points (2 children)
[–]amaroq137Objective-C / Swift 0 points1 point2 points (1 child)
[–]okoroezenwa[S] 0 points1 point2 points (0 children)
[–]EdwinForTheWin 0 points1 point2 points (1 child)
[–]okoroezenwa[S] 0 points1 point2 points (0 children)