UIImageView instances of NSPathStore2 leaked

I have the issue too.

Reproduce

Just create clean new project to reproduce the issue.

  1. Drag image.png to project, make sure it in Copy Bundle Resources.
  2. Write these two lines in viewDidLoad.
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let path = Bundle.main.path(forResource: "image", ofType: "png")!
        let _ = UIImage(contentsOfFile: path)
    }
}
  1. Build and Run it.
  2. Click Debug Memory Graph when viewController appeared.
  3. You can see leak issues.

Not sure is it a bug of init(contentsOfFile:)?

Solution

I changed the API init(data:) instead of init(contentsOfFile:) to solve the problem.

let url = Bundle.main.url(forResource: "image", withExtension: "png")!
let imageData = try! Data(contentsOf: url)
let _ = UIImage(data: imageData)

Using Xcode 11.5/11.3.1 and Swift 5