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

Memory leak of ProjectImpl and GitRepositoryImpl after project is closed #255

Closed
1 of 3 tasks
radomirm-g opened this issue Oct 29, 2019 · 2 comments
Closed
1 of 3 tasks

Comments

@radomirm-g
Copy link

  • I'm submitting a ...

    • bug report
    • feature request
    • puppy => You're not submitting a puppy. I already have one and he's adorable
  • What is the current behavior?
    Android Studio team noticed memory reports from our users, where gitflow leaks objects related to projects that has already been closed.

  • Is this a bug? Sorry about that. If so give me explicit details how to reproduce:

  1. Open Android Studio
  2. Open a project
  3. Close the project
  4. Reopen same project
  5. Inspect heap in a profiler: the instance of ProjectImpl of the closed project is kept alive due to gitflow plugin.
  • What is the expected behavior?
    gitflow should not store references to large objects like ProjectImpl after the project has been closed. Depending on what the ProjectImpl references, the memory leak can be from 20MB to over 100MB.

  • What is the motivation / use case for changing the behavior?
    Lower memory consumption of gitflow plugin in Android Studio.

  • Please tell me about your environment:

    • Gitflow4idea version: 0.7.0
      Reproduced on Android Studio 4.0 Canary 1, likely affects all versions of Android Studio and IntelliJ Idea.
  • Other information (e.g. detailed explanation, stacktrace, related issues, suggestions how to fix, links for me to have context words of praises, pictures of puppies (again with the puppy??) )

Relevant part of a memory report:

Disposed but still strong-referenced objects: 1 com.intellij.openapi.project.impl.ProjectImpl, most common paths from GC-roots:
[    1/100%/  102B] 59.1MB          1   ROOT: Static field: gitflow.GitflowConfigUtil.gitflowConfigUtilMap
[    1/100%/  102B] 59.1MB          1   (root): java.util.HashMap
[    1/100%/  102B] 59.1MB          1   table: java.util.HashMap$Node[]
[    1/100%/  102B] 59.1MB          1   []: java.util.HashMap$Node
[    1/100%/  102B] 59.1MB          1 * key: com.intellij.openapi.project.impl.ProjectImpl (disposed)

Disposed but still strong-referenced objects: 1 git4idea.repo.GitRepositoryImpl, most common paths from GC-roots:
[    1/100%/   88B]  611KB          1   ROOT: Static field: gitflow.GitflowBranchUtilManager.repoBranchUtilMap
[    1/100%/   88B]  611KB          1   (root): java.util.HashMap
[    1/100%/   88B]  611KB          1   table: java.util.HashMap$Node[]
[    1/100%/   88B]  585KB          1   []: java.util.HashMap$Node
[    1/100%/   88B]  583KB          1 * key: git4idea.repo.GitRepositoryImpl (disposed)

In the report above, the memory leak is ~60MB. For some projects it can be even more and a new leak happens every time a project is closed.

GitflowConfigUtil.gitflowConfigUtilMap uses ProjectImpl as a key in the map and GitflowBranchUtilManager.repoBranchUtilMap uses GitRepositoryImpl instance as a key, Neither of the maps removes the reference when project is closed.

For entries in repoBranchUtilMap, consider adding a following code inGitflowBranchUtilManager.setupBranchUtil:

Disposer.register(repo, () -> repoBranchUtilMap.remove(repo));

For gitflowConfigUtilMap, consider similar pattern or use ProjectManagerListener.projectClosed event to remove the key from the map.

@OpherV
Copy link
Owner

OpherV commented Oct 30, 2019

Thanks so much for this report. I'll include this in the next version

@OpherV OpherV mentioned this issue Dec 5, 2019
3 tasks
@OpherV
Copy link
Owner

OpherV commented Dec 13, 2019

@radomirm-g which tool did you use to receive this output of memory allocation?

@OpherV OpherV closed this as completed in 09bd4a1 Dec 13, 2019
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

No branches or pull requests

2 participants