How to find ClassLoader leaks

  • load heapdump in eclipse MAT
  • create histogram
  • group classes by classloader
  • among others we can see several ChildFirstClassLoader objects, these are the user classloaders. Because they are still around, something is leaking it
  • select one of these entries, and merge the shortest paths to GC roots
  • there is now one entry for the system classloader
  • drilling down into it we find the java.sql.DriverManager
  • the contained registeredDrivers array contains multiple drivers for druid, postgresql and calcite
  • select any of these drivers, use Java Basics -> Class Loader explorer
  • you are now shown a ChildFirstClassLoader
  • This means that the driver originates from the user classloader, but is referenced from the system classloader. If the reference in the latter is not removed (due to improper cleanup), then the user classloader cannot be garbage collected.


How to resolve Classloader Leaks

Understand the ClassLoading infrastructure of Flink, as well as approaches (deployment options, configuration options and hooks for your user code) for resolving those issues. https://ci.apache.org/projects/flink/flink-docs-master/docs/ops/debugging/debugging_classloading/

  • No labels

2 Comments

  1. Should we add something here about a recommended action? Like add a Class Loader Cleanup Hook? (Robert Metzger) ? 

    1. I linked to the respective Flink documentation page, that also mentions the cleanup hook.