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

Prevent memory churn described in #208 #209

Merged
merged 3 commits into from
Dec 19, 2022

Conversation

darronschall
Copy link
Contributor

@darronschall darronschall commented Oct 17, 2022

Fixes #208

Accessing stateFlow.value is not guaranteed to always return the same instance even when the underlying value is unchanged. This stateFlow behavior was incorrectly causing infinite objectWillChange events due to the equality test always reporting false even when the new value was, in fact, equal to the previous.

The fix is to go through isEqual(to:) to compare the value contents to determine equality before firing off an objectWillChange event.

Accessing `stateFlow.value` is not guaranteed to always return the same instance even when the underlying value is unchanged. This  stateFlow behavior was incorrectly causing infinite `objectWillChange` events due to the equality test always reporting `false` even when the new value was, in fact, equal to the previous.

The fix is to go through [`isEqual(to:)`](https://developer.apple.com/documentation/foundation/nsarray/1411770-isequal) to compare the value _contents_ when determine equality before firing off an `objectWillChange` event.
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Alex009 Alex009 requested a review from kramlex October 28, 2022 06:16
@Alex009 Alex009 added this to the 0.15.0 milestone Oct 28, 2022
@Alex009 Alex009 linked an issue Oct 28, 2022 that may be closed by this pull request
@Alex009
Copy link
Member

Alex009 commented Oct 28, 2022

@kramlex check this please

@kramlex
Copy link
Contributor

kramlex commented Dec 5, 2022

@Alex009 check this pr please

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Alex009 Alex009 merged commit 263528b into icerockdev:develop Dec 19, 2022
@darronschall darronschall deleted the patch-1 branch March 16, 2024 01:51
darronschall added a commit to darronschall/moko-mvvm that referenced this pull request Mar 16, 2024
This applies the same change made to `state` in icerockdev#209 to `stateNullable` to prevent potential memory churn.
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.

Memory churn when collecting CStateFlow of List due to === test.
3 participants