tiskender2 / StoryUI

Create stories with just single-line code written in SwiftUI
MIT License
45 stars 10 forks source link

Memory leaks #20

Closed clbemre closed 9 hours ago

clbemre commented 3 weeks ago

Hello, firstly i want to say it's great library.

But in general, there are memory leaks in the library. I am still looking. One of the ones I found is this;

ImageLoader class remains in memory and doesn't work deinit

I noticed that when we use URLSession.shared instead of let session = URLSession(configuration: .default, delegate: self, delegateQueue: nil) it is deleted from memory.

Can you check? Because I don't know why you use second option.

Thank you, good work

clbemre commented 3 weeks ago

I don't fully understand if it has an effect, but there is self.player?.addObserver(self, forKeyPath: self.key_timeControlStatus, options: .new, context: nil) in PlayerView, so it may be necessary to add player?.removeObserver(self, forKeyPath: key_timeControlStatus) in deinit.

tiskender2 commented 1 day ago

I have some improvement about caching and memory leak you can try on new release 1.5.5

And also, there is a question about malloc leaks on Stack Overflow for more information

Malloc leaks

clbemre commented 11 hours ago

Firstly, thank you for your interest. I'll check.

I just saw small thing.

@objc private func replaceCurrentItemObserver() {
        self.player?.replaceCurrentItem(with: nil)
        self.player = nil
        NotificationCenter.default.removeObserver(self)
        player?.removeObserver(self, forKeyPath: "timeControlStatus")
    }

Before player?.removeObserver, you assigned nil to the player.

@objc private func replaceCurrentItemObserver() {
        self.player?.replaceCurrentItem(with: nil)
        NotificationCenter.default.removeObserver(self)
        player?.removeObserver(self, forKeyPath: "timeControlStatus")
        self.player = nil
    }
----    ----    ----    ----    ----    ----    ----    ----    ----    ----    ----    
// also i can't understood why passed inject storyData and storyData.stories item together
 ForEach(storyData.stories) { model in
                    StoryDetailView(storyData: storyData,
                                      model: model,

Thank you very much Best Regards

tiskender2 commented 9 hours ago

hi again thanks for your review i have made some changes storyData(now it is called as viewModel) is allStories viewmodel and it was @EnvironmentObject changed to @ObservedObject therefore i am getting it on init

clbemre commented 9 hours ago

Thank you, have a nice day 🙏🏻