Skip to content

RUMM-3475: Fix memory leak in JankStats usage#1553

Merged
0xnm merged 1 commit into
developfrom
nogorodnikov/rumm-3475/fix-jankstats-memory-leak
Jul 24, 2023
Merged

RUMM-3475: Fix memory leak in JankStats usage#1553
0xnm merged 1 commit into
developfrom
nogorodnikov/rumm-3475/fix-jankstats-memory-leak

Conversation

@0xnm

@0xnm 0xnm commented Jul 24, 2023

Copy link
Copy Markdown
Member

What does this PR do?

There is a memory leak in the structure like WeakHashMap<Window, JankStats>, because WeakHashMap has strongly-referenced values, so it means if JankStats holds internally Window instance, it won't be GC-ed, even if it is a key of WeakHashMap.

In this PR we are removing the keys explicitly if activity is destroyed and there are no more activities left. This may increase the number of times we create JankStats instance, but it is not a big deal compared to the memory leak mitigation.

Even if there is a configuration change and activity will be re-created, it may be backed by new/another window anyway.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm
0xnm requested a review from a team as a code owner July 24, 2023 15:45
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #1553 (c20c477) into develop (01ece69) will decrease coverage by 0.08%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1553      +/-   ##
===========================================
- Coverage    83.39%   83.31%   -0.08%     
===========================================
  Files          437      437              
  Lines        14746    14749       +3     
  Branches      2219     2220       +1     
===========================================
- Hits         12297    12287      -10     
- Misses        1868     1872       +4     
- Partials       581      590       +9     
Impacted Files Coverage Δ
...ernal/vitals/JankStatsActivityLifecycleListener.kt 85.71% <100.00%> (+0.81%) ⬆️

... and 12 files with indirect coverage changes

@0xnm
0xnm merged commit e65d397 into develop Jul 24, 2023
@0xnm
0xnm deleted the nogorodnikov/rumm-3475/fix-jankstats-memory-leak branch July 24, 2023 16:35
@xgouchet xgouchet added this to the 2.0.0 milestone Dec 13, 2023
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.

4 participants