-
Notifications
You must be signed in to change notification settings - Fork 266
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: org.sqlite.JDBC holds classloader of KSP #1063
Comments
@ting-yuan @neetopia |
Should we try to open an issue on Sqlite too? |
The SQLite library used by Room registers the JDBC driver in a static block and thus conveniently has the driver available but never unregister it. In a normal application, this would be fine since they tend to have a single class loader, but in Gradle builds, multiple class loaders are used and the driver is registered multiple times without ever being unregistered, this can lead to memory leaks. To avoid leaks, Room tries to manage the life of the driver by unregistering it once processing is done. In the case that the same instance of Room is used to do new processing, Room re-registers the driver since using the same instance of Room would mean the same class loader and JDBC's static block and driver registering logic would not execute. Re-register a driver that is already present is a no-op. See: google/ksp#1063 Test: Verified manually with sample project in linked bug. Change-Id: I8916fd0bcb42337314feebef9afa0b54d4f479bc
This is fixed in Room already. It is also mitigated in #1067 in case there are other processors with similar issue. |
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. 👏 👏 |
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! 👏 👏 🍰 |
This happens when running Room:
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.Here is a sample project thanks to @BugsBunnyBR.
The text was updated successfully, but these errors were encountered: