Open
Description
🐞 Deprecated API Usage: UIGraphicsBeginImageContextWithOptions
may cause crash in low-memory
Hi, I noticed that this library is using the deprecated UIGraphicsBeginImageContextWithOptions
API in the following line:
SDWebImageSwiftUI/SDWebImageSwiftUI/Classes/WebImage.swift
Lines 211 to 214 in ea24105
Apple has marked this API as deprecated (with version 100000
) and recommends replacing it with UIGraphicsImageRenderer
.
💥 Crash Context (low-memory device)
In some cases, especially on devices with low memory, the following crash can occur:
Fatal Exception: NSInternalInconsistencyException
UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={...}, scale=..., bitmapInfo=...
Use UIGraphicsImageRenderer to avoid this assert.
📉 Deprecation Info
@available(iOS, introduced: 4.0, deprecated: 100000, message: "Replace usage of UIGraphicsBeginImageContextWithOptions with UIGraphicsImageRenderer.")
public func UIGraphicsBeginImageContextWithOptions(_ size: CGSize, _ opaque: Bool, _ scale: CGFloat)
@available(iOS, introduced: 2.0, deprecated: 100000, message: "Replace usage of UIGraphicsBeginImageContext with UIGraphicsImageRenderer.")
public func UIGraphicsBeginImageContext(_ size: CGSize)
@available(iOS, introduced: 2.0, deprecated: 100000, message: "Replace usage of UIGraphicsGetImageFromCurrentImageContext with UIGraphicsImageRendererContext.currentImage.")
public func UIGraphicsGetImageFromCurrentImageContext() -> UIImage?
@available(iOS, introduced: 2.0, deprecated: 100000, message: "UIGraphicsEndImageContext should only be used alongside UIGraphicsBeginImageContext[WithOptions].")
public func UIGraphicsEndImageContext()
✅ Kingfisher Reference
For reference, this has already been fixed in Kingfisher in the following PR:
💡 Suggestion
Would you consider updating SDWebImageSwiftUI to use UIGraphicsImageRenderer
instead?
It’s safer and preferred in modern iOS development, and avoids low-memory crashes.
Thanks for your great work on this library! 🙏