question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak: org.sqlite.JDBC holds classloader of KSP

See original GitHub issue

This happens when running Room:

  1. Kotlin compiler daemon loads compiler plugins (KSP) with a new class loader every time it gets a request from Gradle.
  2. KSP loads processors(Room) with a child classloader.
  3. Room uses org.sqlite.JDBC, which is also loaded with Room’s classloader.
  4. org.sqlite.JDBC’s static initializer calls java.sql.DriverManager.registerDriver, which stores the class org.sqlite.JDBC in a static member of java.sql.DriverManager.
  5. java.sql.DriverManager is loaded by the root classloader.
  6. Therefore all everything loaded with KSP’s classloader can also be reached by the root classloader and never be GC’ed.

Here is a sample project thanks to @BugsBunnyBR.

Screenshot 2022-08-13 01 37 09

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
BugsBunnyBRcommented, Oct 16, 2022

So, I updated ksp/kotlin/room to the latest version and ran the benchmark again. The behaviour of the memory consumption improved by a lot! Not only that, but the number of live threads stabilised too. Great work folks! 👏 👏 🍰

Screenshot 2022-10-16 at 12 40 38

0reactions
BugsBunnyBRcommented, Aug 25, 2022

To the people watching this issue…

I ran the benchmark in a branch with the latest version of room and these are the results. Screenshot 2022-08-25 at 15 49 40

This is way better than before, even though it seems to use lots of memory I was able to run 50 iterations and didn’t get an out of memory. 👏 👏 I will be waiting a version of ksp to verify the final results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak with JDBC / SQLite - java - Stack Overflow
We run sqlite-jdbc in a production environment and we noticed similar behavior when inspecting heap dumps. These objects are only on the ...
Read more >
Tomcat Warning “To Prevent a Memory Leak, the JDBC Driver ...
When we undeploy the web application, its class loader is garbage collected. On the other hand, the DriverManager still references the JDBC ......
Read more >
Dynamic Memory Allocation In SQLite
At the end of each script, all objects are destroyed and a test is made to ensure that all memory has been freed....
Read more >
availables.xml - MIT
plugin allows you to see colors used in Java code and CSS/HTML files. You may also picks colors and insert one of several...
Read more >
log: com.starry.greenstash:8 - F-Droid Monitor
Annotation processing mode: apt Memory leak detection mode: none Show ... /.gradle/caches/modules-2/files-2.1/org.xerial/sqlite-jdbc/3.36.0/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found