0

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.

Selonath
  • 23
  • 3
  • Try by reducing the image scale value as less than 1.0 (say 0.3, 0.4, etc...) – Karthick Selvaraj Nov 07 '16 at 13:27
  • Thanks but not thats my problem. My problem is I can not remove this from my memory at all. When I do an unwind segue, it has to be removed. But no. They are still there. And If I reopen that viewcontroller again.. it will be 150Mb, and 200 and 250 and so on.. These images never will be removed from the memory. Thats my problem. – Selonath Nov 07 '16 at 14:45

0 Answers0