Skip to content

Weakly reference Activity for transaction finished callback#2203

Merged
adinauer merged 5 commits into
mainfrom
feat/fix-activity-leak
Aug 3, 2022
Merged

Weakly reference Activity for transaction finished callback#2203
adinauer merged 5 commits into
mainfrom
feat/fix-activity-leak

Conversation

@adinauer

@adinauer adinauer commented Aug 3, 2022

Copy link
Copy Markdown
Member

📜 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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.

}

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

Copy link
Copy Markdown
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
Copy Markdown
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

codecov-commenter commented Aug 3, 2022

Copy link
Copy Markdown

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.

@adinauer
adinauer requested a review from marandaneto August 3, 2022 13:20
options
.getLogger()
.log(
SentryLevel.WARNING,

Copy link
Copy Markdown
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