Thanks. So it sounds like the NSImage is getting over-released or being incorrectly deallocated, although it's unclear to me what exactly is trying to form a weak reference, since my code (as shown above) has a strong reference. Unfortunately the higher up function calls are made by AppKit, which is not open source, so I cannot look it up.
As far as I understand, the link you posted helps investigating memory issues in Xcode, but since the crash reports are downloaded by Xcode from other users and I cannot reproduce it myself...
The Xcode statistics seem to show that it only happens with macOS 15.3 or newer. I don't know if it's because there's not enough space to show older releases, or if it's really a clue that it's a change introduced with macOS 15.3 that causes this issue.
From my perspective it would make sense that it's a new issue with macOS 15.3, because I haven't changed the code that generates or assigns that image in a very long time, and this issue didn't happen for a previous version of my app that was live on the App Store for 6 months (starting from about one year ago) and had barely any crashes (all unrelated to this one).
Perhaps it helps to share how the image is created. The result of the method below is directly assigned to myEntity.image in the code I posted originally. Could any of the used APIs have a bug that causes the image to be released incorrectly?
private func image(url: URL?) -> NSImage {
if let url = url {
let imageURL: URL
if let volumeURL = (try? url.resourceValues(forKeys: [.volumeURLKey]))?.volume, volumeURL.path != "/" {
imageURL = volumeURL
} else {
imageURL = url
}
return (try? imageURL.resourceValues(forKeys: [.effectiveIconKey]))?.effectiveIcon as? NSImage ?? NSImage(named: NSImage.folderName)!
} else {
return NSImage(systemSymbolName: "questionmark.diamond.fill", accessibilityDescription: nil)!.withSymbolConfiguration(.init(paletteColors: [NSColor(white: 0.95, alpha: 1), .systemPurple]))!
}
}