Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebImage in LazyVStack take massive memory #271

Open
ywwzwb opened this issue Jul 24, 2023 · 9 comments
Open

WebImage in LazyVStack take massive memory #271

ywwzwb opened this issue Jul 24, 2023 · 9 comments

Comments

@ywwzwb
Copy link

ywwzwb commented Jul 24, 2023

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.

image

@edolorenza
Copy link

Does this only happen on iOS 17 ?

@ywwzwb
Copy link
Author

ywwzwb commented Sep 23, 2023

I tested it on iOS16, both on simulator and iPhone device. @edolorenza

@dreampiggy
Copy link
Collaborator

Have a try with the latest v3.0.0-Beta or master branch ? Is this still reproducable ?

@ywwzwb
Copy link
Author

ywwzwb commented Sep 23, 2023

I have tried 3.0.0-beta with iOS16.6.1 on my iPhone, and seems using less memory than before.
image
but the memory skill keep growing while scrolling the image list.

@ywwzwb
Copy link
Author

ywwzwb commented Sep 23, 2023

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()
    }
}

@frandelarosa
Copy link

I'm using a LazyVStack for my project and I can confirm that. CPU is between 90% - 98% during the scroll.

@Sharrykhan01
Copy link

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.

@ashishsj0
Copy link

Has there been an update on this? Facing something similar with AnimatedImage.

@dreampiggy
Copy link
Collaborator

dreampiggy commented Nov 4, 2024

acing something similar with AnimatedImage.

Provide a demo ? AnimatedImage actually use UIKit View, so it has no storage itself at all. It the same like UIKit when you written UICollectionViewCell and I didn't here anything about this issue. Because the re-use of cell is handled by UIKit, not by us. (Maybe bugs of SwiftUI ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants