Fix memory leak when deleting project #6296
Merged
+29
−48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #6280
I ended up fixing this because I kept running into it while working on something else.
The key problem here was that we tried to unregister our settings listener for fragment like this:
In the case where we delete a project, this ends up getting called after the project has changed meaning that
settingsProvider.getProtectedSettings()
will return a differentSettings
object than was used to register. To prevent this situation, I've made it so that preferences Fragments assign theirSettings
object inonAttach
. As far as I'm aware, there's no reason for this to be looked up each time.Why is this the best possible solution? Were any other approaches considered?
I did consider adding a constructer for
BaseProjectPreferencesFragment
andBaseAdminPreferencesFragment
that would take a project ID rather than needing to do a lookup based onProjectDataService
. That would be more canoncial now that we haveFragmentFactory
. That change would ripple down to many subclasses though, so I felt like it was best to avoid while trying to just make a small fix.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Should just fix the leak!
Before submitting this PR, please make sure you have:
./gradlew connectedAndroidTest
(or./gradlew testLab
) and confirmed all checks still passDateFormatsTest