fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.27k stars 168 forks source link

[FEAT] Some way to define how many pages will be kept in memory #276

Closed mvrsn closed 2 years ago

mvrsn commented 2 years ago

Is your feature request related to a problem? Please describe. One of the uses I have for SwiftUIPager is to load pages on demand, but after some time memory starts going up, especially due to the nature of what I have in each page

Describe the solution you'd like It would be great to have some way to define some limit of how many pages are kept in memory, or to have some API for manually removing pages by index

Notes I had a look at https://github.com/fermoya/SwiftUIPager/issues/186 which suggests to use the eager loading policy, but that will not be a solution for me according to the docs as there could be hundreds or thousands of pages in my use-case

fermoya commented 2 years ago

@mvrsn Pager keeps by default a handful of pages in memory. Using .eager isn't recommended.

Please take a look at this section. Just about 5 pages are kept in memory depending on the page size

mvrsn commented 2 years ago

Thank you for the quick response @fermoya

What made me confused is that I am loading webviews into the Pager pages, and when I check the Safari developer tools I can see webviews listed under my device that should no longer exist, however, I now tested and modified the contents of one of the old webviews while outside the range of kept-in-memory webviews before navigating back, and indeed you are correct, a new one was created and the modifications are not shown

I'm not sure why the webviews are still visible within Safari though, even after restarting the program, but maybe this has something to do with the garbage collection of iOS that they are still there?