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

Fix retain cycle and VM recreation #275

Merged
merged 2 commits into from Jun 29, 2020

Conversation

RuiAAPeres
Copy link
Contributor

What

This PR addresses two issues with the VillagersViewModel. In particular with its recreation whenever SwiftUI dictates so and the implicit use of self as part of its implementation.

How

  1. Make self weak and avoid the map's closure capturing self.
  2. Use StateObject instead of ObservedObject. Although I am not particular fond of this approach, it fixes the problem where VillagersViewModel is being recreated every time the user switches tab on TodayBirthdaysSection.

This problem can be seen here:

Before After (with this PR)
before after

We can also see the memory growing with the implicit self capture:

Before After
image image

@Dimillian
Copy link
Owner

Perfect!

@Dimillian Dimillian merged commit 3ac29a8 into Dimillian:main Jun 29, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants