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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retained size computation is incorrect #2715

Open
pyricau opened this issue Sep 24, 2024 · 0 comments
Open

Retained size computation is incorrect #2715

pyricau opened this issue Sep 24, 2024 · 0 comments

Comments

@pyricau
Copy link
Member

pyricau commented Sep 24, 2024

Context: https://androiddev.social/@py/113176281321505098

Repro:

  @Test fun `Updating first dominator through longer path after already updated to common ancestor denominator removes retained size`() {
    hprofFile.dump {
      val answer = string("42")
      val life = "com.example.Life" instance { field["answer"] = answer }
      val universe = "com.example.Universe" instance { field["answer"] = answer }
      val everything = "com.example.Everything" watchedInstance {
        field["life"] = life
        field["universe"] = universe
      }
      val fiber = "com.example.Fiber" instance { field["life"] = life }
      val towel = "com.example.Towel" instance { field["fiber"] = fiber }
      "Hitchhiker" clazz {
        staticField["guide"] = everything
        staticField["practicalTool"] = towel
      }
    }

    val everythingInstanceLeak = retainedInstances().single().leakTraces.first()
    // Only "Universe" is dominated by "Everything", the watched instance.
    // shallow size for "everything" is 2 refs (life + universe) => 8 bytes
    // Universe has one ref: 4 bytes => 8 + 4 = 12.
    // Instead we get 24 because the incorrect algorithm is including the answer string
    // which is 4 bytes for int size, 2 bytes per char => 12 bytes
    assertThat(everythingInstanceLeak.retainedObjectCount).isEqualTo(2)
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant