I am loading png images from the Document directory into an UIImageView. When using the xcode Debug memory graph it comes up with Memory issues:
instances of NSPathStore2 leaked
I have heard that the instrument's leak tool can report false leaks.
The memory seems to not go up:
The problem seems to be in UIImage, see Instruments Leak report:
Here is the code that produces the images:
try FileManager.default.copyfileToUserDocumentDirectory(forResource: "smiley", ofType: ".png")
var fullPathString = ""
if let docDir = NSSearchPathForDirectoriesInDomains(.documentDirectory,
.userDomainMask,
true).first {
let fileName = "smiley.png"
let fullDestPath = URL(fileURLWithPath: docDir).appendingPathComponent(fileName)
fullPathString = fullDestPath.path
}
mainStackView.addArrangedSubview(UIImageView(image: UIImage(contentsOfFile: fullPathString)))
mainStackView.addArrangedSubview(UIImageView(image: UIImage(contentsOfFile: fullPathString)))
The working project producing this problem can be found here: UIImageViewNSPathStore2leaked
Is there a way to change the code so that these leaks go away, or is this one of those false reports?
init(contentsOfFile:)
– Backspin