Memory leak: org.sqlite.JDBC holds classloader of KSP
See original GitHub issueThis happens when running Room:
- Kotlin compiler daemon loads compiler plugins (KSP) with a new class loader every time it gets a request from Gradle.
- KSP loads processors(Room) with a child classloader.
- Room uses
org.sqlite.JDBC
, which is also loaded with Room’s classloader. org.sqlite.JDBC
’s static initializer callsjava.sql.DriverManager.registerDriver
, which stores the classorg.sqlite.JDBC
in a static member ofjava.sql.DriverManager
.java.sql.DriverManager
is loaded by the root classloader.- 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.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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! 👏 👏 🍰
To the people watching this issue…
I ran the benchmark in a branch with the latest version of room and these are the results.
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.