I hope I am not posting a duplicate question here, but I am stuck and don’t really know how to debug this.
So, I have build my first iOS app with SwiftUI using SwiftData for persistence. I am very very new to Swift and mobile development as a whole.
What I’ve done is save a calendar object that is retrieved in the home view. Once the user selected his calendar, I always pass the object down to all the child views as a @Bindable object.
One view is the yearly calendar where I show all the months of the year in a LazyVStack within a ScrollView.
Today I’ve noticed that the memory usage increases steadily when I scroll up and down and up and down. After some digging, I found out that I have memory leaks.
So part one of my question up front would be: what would be the best practice to share one central object with all children so they can easily interact with it. (That’s the reason why I’ve passed the object as a @Bindable. It was so easy to directly alter it’s properties)
The other part of my question would be. How does one – who knows as little as I do – go about debugging such fun little errors like memory leaks. I am pretty stuck right about now.
My code structure:
- HomeView queries for all calendars. Once user selects a calendar,
- CalendarHomeView appears and gets the reference to the selected Calendar as a @Bindable. My home view has a
- CurrentWeekView that also gets the @Bindable. This view has a button to open the
- YearView that – you guessed it – gets the cal as a @Bindable.
This is my very first project and I tried to learn as much as possible just by simply building out my app idea. So I am pretty sure my structure and design are pretty bad .. but yeah. Maybe anyone is patient enough to help me out with a little guidance on how a real mobile developer would go about this?
Thanks! 🙂