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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weakly reference Activity for transaction finished callback #2203

Merged
merged 5 commits into from Aug 3, 2022

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented Aug 3, 2022

馃摐 Description

Wrap Activity with WeakReference in ActivityLifecycleIntegration to not strongly hold on to it for the TransactionFinishedCallback.

馃挕 Motivation and Context

Fixes #2201

馃挌 How did you test it?

Emulator

馃摑 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

馃敭 Next steps

@adinauer adinauer requested a review from romtsn as a code owner August 3, 2022 08:35
Comment on lines 173 to 175
if (unwrappedActivity != null) {
activityFramesTracker.setMetrics(activity, finishingTransaction.getEventId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd log in to the else branch, so people know why frames were not attached in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

Copy link

Choose a reason for hiding this comment

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

image

is still use activity , replace by unwrappedActivity?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you looked at some old version of the code in this PR. It's using the unwrappedActivity now. I unintentionally commited the code I played around with to confirm the fix and then fixed with another commit.

@@ -146,6 +147,7 @@ private void stopPreviousTransactions() {
}

private void startTracing(final @NotNull Activity activity) {
WeakReference<Activity> weakActivity = new WeakReference<>(activity);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please try to reproduce the issue with and without the fix using LeakCanary.
Upgrade leakcanary to the latest version -> https://github.com/square/leakcanary/releases/tag/v2.9.1

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried with 2.9.1 but it didn't find anything regardless of WeakReference or old implementation.

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2022

Codecov Report

Merging #2203 (8946e0f) into main (4eb446a) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##               main    #2203   +/-   ##
=========================================
  Coverage     80.90%   80.90%           
  Complexity     3313     3313           
=========================================
  Files           236      236           
  Lines         12155    12155           
  Branches       1616     1616           
=========================================
  Hits           9834     9834           
  Misses         1725     1725           
  Partials        596      596           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

options
.getLogger()
.log(
SentryLevel.WARNING,
Copy link
Member Author

Choose a reason for hiding this comment

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

What log level should this be?

@adinauer adinauer merged commit 3c24dd4 into main Aug 3, 2022
@adinauer adinauer deleted the feat/fix-activity-leak branch August 3, 2022 16:43
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.

ActivityLifecycleIntegration.class would cast mem leak
4 participants