SDWebImageSwiftUI
SDWebImageSwiftUI copied to clipboard
WebImage in LazyVStack take massive memory
I write a demo with SDWebImageSwiftUI, just put some images in a lazyVStack. here is code for the demo:
struct ContentView: View {
@State private var ImageURLList: [String] = []
var body: some View {
GeometryReader { geometryProxy in
VStack {
HStack{
Button("test load") {
// parse the image list...
}
Spacer()
Button("clear") {
ImageURLList.removeAll()
}
}
ScrollView {
LazyVStack(spacing: 0) {
ForEach(ImageURLList, id: \.self) { url in
ImageBodyView(url: url)
.scaledToFit()
.frame(width: geometryProxy.size.width)
}
}
}
}
}
.padding()
}
struct ImageBodyView: View {
@State var url: String
var body: some View {
VStack {
WebImage(url: URL(string: url))
.resizable()
}
}
}
}
this demo using a lots of memories, and it will keep growing while scrolling to the bottom. The memory will not release before I clean the imageUrlList.
Does this only happen on iOS 17 ?
I tested it on iOS16, both on simulator and iPhone device. @edolorenza
Have a try with the latest v3.0.0-Beta or master branch ? Is this still reproducable ?
I have tried 3.0.0-beta with iOS16.6.1 on my iPhone, and seems using less memory than before.
but the memory skill keep growing while scrolling the image list.
Here is a full demo, which will load some images of cat, hope it helps.
struct ImageBodyView: View {
@State var url: String
var body: some View {
VStack {
WebImage(url: URL(string: url))
.resizable()
}
}
}
struct ContentView: View {
@State private var imageURLList: [String] = []
var body: some View {
GeometryReader { geometryProxy in
VStack {
HStack{
Button("test load") {
self.imageURLList = (1..<100).map{ "https://cataas.com/cat?r="+String($0) }
}
Spacer()
Button("clear") {
self.imageURLList.removeAll()
}
}
ScrollView {
LazyVStack(spacing: 0) {
ForEach(self.imageURLList, id: \.self) { url in
ImageBodyView(url: url)
.scaledToFit()
.frame(width: geometryProxy.size.width)
}
}
}
}
}
.padding()
}
}
I'm using a LazyVStack for my project and I can confirm that. CPU is between 90% - 98% during the scroll.
Yes it do occur while scrolling the memory raises and unexpectedly gets crashed too. Please if you find something to release out the memory, do inform me too.