iOS reminiscence leak when changing a UIImage

0
23


I’ve written just a little iOS app which creates a slideshow primarily based on pictures saved within the Paperwork listing (beneath Information).

It really works however I suppose it is leaking reminiscence. The explanation I say it’s because when working it, I see the reminiscence creeping up in XCode every time a picture is changed.

It isn’t very difficult. I’ve:

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        
        self.imageView.contentMode = .scaleAspectFill
        self.imageView.body = CGRect(
            x: 0,
            y: 0,
            width: self.bounds.measurement.width,
            top: self.bounds.measurement.top
        )
        
        view.addSubview(self.imageView)
        
        /* Masses the filenames of the pictures */
        loadImages()
        
        displayNext()
         
        Timer.scheduledTimer(
            timeInterval: self.cycleSeconds,
            goal: self,
            selector: #selector(displayNext),
            userInfo: nil,
            repeats: true
        )
    }

    @objc
    func displayNext() {
        let imageURL = self.documentsURL.appendingPathComponent(self.imageNames[self.imageIndices[self.i]])
        
        replaceImage(with: imageURL)
        
        if self.i + 1 == self.imageNames.depend {
            shuffleImageIndices()
            self.i = 0
        } else {
            self.i = self.i + 1
        }
    }

The code displayNext() ultimately calls this code beneath to transition to the following picture:

    func replaceImage(with imageURL: URL) {
        assert(imageURL.isFileURL)
        
        let nextImage = UIImage(named: imageURL.path)

        UIView.transition(
            with: self.imageView,
            period: 0.1,
            choices: .transitionCrossDissolve,
            animations: { self.imageView.picture = nextImage },
            completion: nil
        )
    }

One way or the other all this leaks reminiscence and I am unable to appear to determine methods to do away with it.