ALAsset assetForURL导致从未发布的重要分配

Jea*_*ent 5 memory-leaks memory-management ios swift

我使用轮播在我的应用程序中显示本地图片.

每次重新加载视图时,我都可以在"仪器"上看到"分配"工具,我的应用程序为图像分配内存,但从未发布过.

在此输入图像描述

您可以在下面看到代码:

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)
            }
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经找到了关于这个问题的话题,但我仍然是我的问题:

有什么建议吗?