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 memory leak when deleting project #6296

Merged
merged 6 commits into from
Aug 29, 2024

Conversation

seadowg
Copy link
Member

@seadowg seadowg commented Jul 30, 2024

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:

settingsProvider.getProtectedSettings().unregisterOnSettingChangeListener(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 different Settings object than was used to register. To prevent this situation, I've made it so that preferences Fragments assign their Settings object in onAttach. 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 and BaseAdminPreferencesFragment that would take a project ID rather than needing to do a lookup based on ProjectDataService. That would be more canoncial now that we have FragmentFactory. 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:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@seadowg seadowg marked this pull request as ready for review July 30, 2024 16:18
@seadowg seadowg requested a review from grzesiek2010 July 30, 2024 16:18
@Named("ADMIN_SETTINGS_STORE")
SettingsStore adminSettingsStore;
String projectId;
Settings adminSettings;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those should be private I think.

@seadowg seadowg force-pushed the project-delete-mem-leak branch from 5cc17a6 to 9866b5b Compare August 29, 2024 11:35
@grzesiek2010 grzesiek2010 self-requested a review August 29, 2024 12:07
@grzesiek2010 grzesiek2010 merged commit 2dff662 into getodk:master Aug 29, 2024
6 checks passed
@seadowg seadowg deleted the project-delete-mem-leak branch August 29, 2024 15:14
@WKobus
Copy link

WKobus commented Aug 30, 2024

Tested with Success!

Verified on device with Android 10, 14

Verified cases:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leak after deleting a project
3 participants