Does Postgres JDBC LazyCleaner cause a classloader memory leak?
14:37 14 Mar 2024

I have a Spring Boot web application which is deployed multiple times a day, so a clean undeploy is essential. Tomcat is reporting a memory leak, and MAT points me to

Path to GC Root

I'm using postgresql-42.6.0.jar, and have placed that JAR in the Tomcat 10.1 ./lib directory (as JDBC drivers should be, afaik). It seems to me the web app present at Tomcat startup loads org.postgresql.util.LazyCleaner, which then starts the "PostgreSQL-JDBC-Cleaner" thread. As the thread inherits the AccessControlContext of the ProtectionDomain loaded by the webapp class loader, that class loader will forever have a reference which cannot be gc'ed, ergo a memory leak.

I can't find anything online that others are also having this issue. Am I missing something?

java postgresql tomcat jdbc memory-leaks