fix: Fixing the memory leak introduced in the DPoP flow#891
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a memory leak in the DPoP flow by preventing the DPoP class from retaining references to Activity or Fragment contexts. The fix ensures that only the application context is stored internally, allowing Activity/Fragment contexts to be properly garbage collected.
- Changed the
DPoPclass to storeapplicationContextinstead of the passed context - Updated the constructor parameter to not store the context directly
- Added test mocking for
applicationContextto ensure tests work with the new implementation
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| auth0/src/main/java/com/auth0/android/dpop/DPoP.kt | Modified constructor to extract and store applicationContext instead of storing the passed context directly, preventing memory leaks from Activity/Fragment references |
| auth0/src/test/java/com/auth0/android/dpop/DPoPTest.kt | Added mock setup for applicationContext to support the updated DPoP implementation |
| auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt | Added mock setup for applicationContext to support the updated DPoP implementation |
| auth0/src/test/java/com/auth0/android/authentication/AuthenticationAPIClientTest.kt | Added mock setup for applicationContext to support the updated DPoP implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public class DPoP(context: Context) { | ||
|
|
||
| private val applicationContext: Context = context.applicationContext | ||
|
|
There was a problem hiding this comment.
For my understanding . holding activity context would cause issue DPoP instance lives longer than activity and causing activity to not GC?
sanchitmehta94
approved these changes
Jan 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes
This Pr fixes the memory leak introduced as part of the DPoP flow. The
dpopproperty in theWebAuthProviderclass will retain the instance of the activity/fragment context preventing it from being garbage collected. Updated thecontextin the DPoP class to use anactivityContextinstead.Testing
Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. Since this library has unit testing, tests should be added for new functionality and existing tests should complete without errors.
This change adds unit test coverage
This change adds integration test coverage
This change has been tested on the latest version of the platform/language or why not
Checklist
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors