UIGraphicsImageRenderer memory leak on iOS 18.0

Good morning, when using the following extension I'm getting a memory leak when using Instruments, I've tried capturing self with a weak reference but I still get the leak.

public extension UIImage {
    func resize(_ targetSize: CGSize) -> UIImage {
        let size = self.size
        
        // Calculate the scaling ratios
        let widthRatio = targetSize.width / size.width
        let heightRatio = targetSize.height / size.height
        
        // Determine the scale factor and size to fill the target size
        let scaleFactor = max(widthRatio, heightRatio)
        let scaledImageSize = CGSize(
            width: size.width * scaleFactor,
            height: size.height * scaleFactor
        )
        
        // Calculate the clipping rect
        let clippingRect = CGRect(
            x: (scaledImageSize.width - targetSize.width) / 2.0,
            y: (scaledImageSize.height - targetSize.height) / 2.0,
            width: targetSize.width,
            height: targetSize.height
        )
        
        let format = UIGraphicsImageRendererFormat()
        format.scale = 1
        
        // Render the clipped image
        let renderer = UIGraphicsImageRenderer(size: targetSize, format: format)
        
        return autoreleasepool {
            return renderer.image { _ in
                self.draw(in: CGRect(
                    x: -clippingRect.origin.x,
                    y: -clippingRect.origin.y,
                    width: scaledImageSize.width,
                    height: scaledImageSize.height
                ))
            }
        }
    }
}
Answered by Frameworks Engineer in 811367022

Could you please file a feedback report with a sample project? It would also be helpful to provide a memory graph after running the project and observing the leak. Thanks!

Could you please file a feedback report with a sample project? It would also be helpful to provide a memory graph after running the project and observing the leak. Thanks!

In your bug report please include a small Xcode project and some directions that can be used to reproduce the problem along with some memory graphs, and post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating your bug report.

UIGraphicsImageRenderer memory leak on iOS 18.0
 
 
Q