Skip to content

Conversation

@pmathew92
Copy link
Contributor

Changes

This Pr fixes the memory leak introduced as part of the DPoP flow. The dpop property in the WebAuthProvider class will retain the instance of the activity/fragment context preventing it from being garbage collected. Updated the context in the DPoP class to use an activityContext instead.

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 DPoP class to store applicationContext instead of the passed context
  • Updated the constructor parameter to not store the context directly
  • Added test mocking for applicationContext to 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

Choose a reason for hiding this comment

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

For my understanding . holding activity context would cause issue DPoP instance lives longer than activity and causing activity to not GC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@pmathew92 pmathew92 merged commit 1cb3d84 into main Jan 7, 2026
12 of 17 checks passed
@pmathew92 pmathew92 deleted the dpop_mem_leak branch January 7, 2026 05:25
@pmathew92 pmathew92 mentioned this pull request Jan 7, 2026
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.

3 participants