I have a serious problem that I can not solve. I have a collection view where I load images from iCloud Drive. I use the following code to load images into an image array:
func test() {
for index in 0..<(note?.content?.count)! {
MediaAlbum.imageArray = []
let documentURL = ubiquityURL.URLByAppendingPathComponent((self.note?.content![index].componentsSeparatedByString(";")[0])!)
document = CloudDrive(fileURL: documentURL)
document?.openWithCompletionHandler({(success: Bool) -> Void in
if success {
print("Has Element?:\(MediaAlbum.imageArray)")
} else {
print("error")
}
})
}
}
And loading NSData:
override func loadFromContents(contents: AnyObject, ofType typeName: String?) throws {
if let userContent = contents as? NSData {
userText = NSString(bytes: contents.bytes,
length: userContent.length,
encoding: NSUTF8StringEncoding) as? String
}
if let userContent = contents as? NSData {
userImage = UIImage(data:userContent,scale:1.0)
MediaAlbum.imageArray.append(userImage)
}
}
When this happen everything okay, but when I load images into the Cell's imageView (cell.imageView.image = MediaAlbum.imageArray[indexPath.row])
Memory goes up to 100Mb.
Thats okay but when I close the viewController, or try to clear nothing happened. I analyzed that with Instruments and something hold these images.. But I can not figure out what. Has anyone any idea how can I clear these datas from the memory?
I hope someone could solve that problem, thank you very much.