Memory leak from ALAssetRepresentation CGImage in Swift

I am loading images from assets into my UITableView and I noticed that I am getting a CGImage load related memory leak from defaultAssetRepresentation.fullResolutionImage.CGImage.takeunrevededValue.

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(kReviewDisplayCell, forIndexPath: indexPath) as ReviewDisplayCollectionViewCell
    let asset = assets.objectAtIndex(indexPath.row) as ALAsset
    var cgImage = asset.defaultRepresentation().fullResolutionImage().takeUnretainedValue()
    var orientation:UIImageOrientation?
    var orientationValue:NSNumber = asset.valueForProperty(ALAssetPropertyOrientation) as NSNumber
    orientation  = self.correctOrientation(orientationValue)
    var image = UIImage(CGImage: cgImage, scale: 0.5, orientation: orientation!)
    cell.imageView.image = image

    return cell
}

      

According to the memory leak devices, the leak appears to be related to: NSPathStore2 object. Responsible frame:+[NSPathStore2 pathStoreWithCharacters:Length:]

The above function is called earlier on the stack: -[ALAssetRepresentation _fileDescriptor]

then -[PLGateKeeperClient fileDescriptorForAssetURL:]

I'm sorry, I don't have enough reputation to post my screenshot.

The distribution tool always persists the CGImage from the UITableViewController even after the control manager is disabled by the navigation manager and I can't figure out if there is a strong reference to it somewhere. Is there a way to manually release the CGImage link when using ARC? I tried to put the above code in autoreleasepoool {} but it didn't work. Thanks in advance for your help.

+3


source to share





All Articles