Reduce Memory Consumption when using Large Images | SwiftUI

preview_player
Показать описание
Hello Guys 🖐🖐🖐
In this Video I'm going to teach how to reduce memory consumption of an SwiftUI App when using high resolution images | Downsizing Image View SwiftUI | SwiftUI Downsize Image View | Downsizing UIImage | Swift | SwiftUI Xcode 16 | SwiftUI for iOS 18 | Xcode 16 SwiftUI.
#apple #swiftui #ios #xcode #animation #ui #ux #design

► My Apps

► Support Us

► My MacBook Specs
Xcode Version: 16.1
macOS Version: 15.1 Sequoia

► Social Platforms

Thanks for watching
Make sure to like and Subscribe For More Content !!!
Рекомендации по теме
Комментарии
Автор

Optimizing SwiftUI apps is unfortunately a must ! They end up being slow. Those kind of videos are truly appreciated

pskx
Автор

I literally wanted this today. Thanks so much

umayangaalahakoon
Автор

Great Video

Extra information to understand why large image use more memory
Memory usage depends on image dimensions, not file size. For example, a 1GB image with 100x100 pixels uses less memory than a 50MB image with 5000x5000 pixels. This is because high-resolution images require more memory when decompressed and stored pixel-by-pixel.

For me I usually do it like this

extension UIImage {
func downsample(to pointSize: CGSize, scale: CGFloat = UIScreen.main.scale) -> UIImage? {
guard let imageData = 1.0) else { return nil }

let imageSourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary
guard let imageSource = as CFData, imageSourceOptions) else { return nil }

let maxDimension = max(pointSize.width, pointSize.height) * scale
let downsampleOptions = [
true,
true,
true,
maxDimension
] as CFDictionary

guard let downsampledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, downsampleOptions) else { return nil }
return UIImage(cgImage: downsampledImage)
}
}

then use it like this
Image(uiImage: image.downsample(to: CGSize(width: 180, height: 250)) ?? image)

ixx
Автор

Great video! Love to see some optimization videos using swiftUI. Something I would find helpful is a video about animation hitches, specifically diagnosing and fixing animation hitches. I have been struggling a lot with animation hitches in the scrollView when using a 2 column lazyVGrid showing medium sized images loaded from a URL (using KingFisher). I dont know if I am doing something wrong or if it is lazyVGrid not reusing cells that is the issue. I have had the thought in my head to use UIKit for this reason.

henrikrdergard
join shbcf.ru