ALAsset assetForURL results in important distributions never being released

I use a carousel to display local images in my application.

Every time I reload the view, I can see the "Distribution" tool on the "Tool", which my application allocates memory for images, but never released it.

enter image description here

Below you can see the code:

func carousel(carousel: iCarousel!, viewForItemAtIndex index: Int, var reusingView view: UIView!) -> UIView! { if view != nil { for subview in view.subviews { if let imageView = subview as? UIImageView { imageView.image = nil } subview.removeFromSuperview() } } let newView = UIView(frame: aFrame) self._getImageFromLocalWithPath(aPath, completion : { image in if image != nil { let imageView = UIImageView(image: image!) newView.addSubview(imageView) } } ) return newView } private func _getImageFromLocalWithPath(imagePath : String?, completion : UIImage? -> Void) { autoreleasepool { ALAssetsLibrary.defaultAssetLibrary().assetForURL(NSURL(string : imagePath!), resultBlock: { asset in weak var wasset = asset if wasset != nil { let image = UIImage(CGImage : wasset?.defaultRepresentation().fullScreenImage().takeUnretainedValue()) // This is the incriminated line! completion(image) } }, failureBlock: { error in completion(nil) } ) } } 

I already found topics about this problem, but I still have my problem:

Any suggestion?

+5
source share

Source: https://habr.com/ru/post/1208144/


All Articles