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 in ktlint when used in gradle plugins #1216

Closed
jeremymailen opened this issue Aug 16, 2021 · 5 comments · Fixed by #1407 or ankidroid/Anki-Android#10608
Closed

Memory leak in ktlint when used in gradle plugins #1216

jeremymailen opened this issue Aug 16, 2021 · 5 comments · Fixed by #1407 or ankidroid/Anki-Android#10608

Comments

@jeremymailen
Copy link
Contributor

It appears a memory leak was introduced between ktlint 0.40.0 and 0.41.0. Still present in 0.42.1.
This is based on very similar memory leak bugs filed for two different ktlint gradle plugins:
jeremymailen/kotlinter-gradle#204
JLLeitschuh/ktlint-gradle#507

Memory is leaked on both lint and format. The amount of memory leaked appears proportional to the number or size of files processed.

Looking through the commits, I can't pinpoint the issue yet, but I did notice there were changes to KotlinPsiFileFactory and its management. It may or may not be the source of the leak.

The issue does not appear to be sensitive to the version of gradle or kotlin.

Expected Behavior

Calls to Ktlint.lint() and format() should not leak memory.

Observed Behavior

When called from within gradle plugins which will make these calls multiple times and stay resident in the gradle daemon, memory is leaked over time and eventually the gradle daemon dies of memory exhaustion.

Steps to Reproduce

See linked issues above.

Your Environment

  • Version of ktlint used: 0.41.0 to 0.42.1
  • Name and version of integration used: kotlinter-gradle, ktlint-gradle
  • Version of Gradle used (if applicable): 6.8 to 7.1.1
  • Operating System and version: MacOS
@sir-lazlo
Copy link

Has this been fixed in 0.43.0?

@romtsn
Copy link
Collaborator

romtsn commented Nov 7, 2021

No

@Tapchicoma
Copy link
Collaborator

Possible fix that should be applied in KtLint project: JetBrains/kotlin#4650

@jeremymailen
Copy link
Contributor Author

I believe this issue is fixed in 0.43.0. At least it no longer reproduces in kotlinter-gradle 3.7.0. Curious of anyone can repro it in a different plugin?

@vassilisimon
Copy link

It's still not fix with 0.43.2 for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants