我使用轮播在我的应用中显示本地图片。
每次重新加载视图时,我都可以在“工具”中看到我的应用为图像分配内存的“分配”工具,但从未发布过它。
您可以在下面看到代码:
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)
}
)
}
}
我已经找到了有关此问题的主题,但我仍然存在问题:
有什么建议吗?