UIImageView instances of NSPathStore2 leaked
I have the issue too.
Reproduce
Just create clean new project to reproduce the issue.
- Drag image.png to project, make sure it in Copy Bundle Resources.
- 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)
}
}
- Build and Run it.
- Click Debug Memory Graph when viewController appeared.
- 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