On WildFly, I deployed a small application four times (a.jar, b.jar, c.jar, d.jar), which I am attaching as 2lc.jar. I undeployed the four copies of the application and looked at the WildFly memory via Eclipse Memory Analyzer and could see that four copies of the application classloader was still in memory.
The ByteBuddy TypeCache can be cleared by the Java garbage collector or by manually calling ByteBuddy TypeCache#expungeStaleEntries().
The question is when should we call TypeCache#expungeStaleEntries()? If we could call that at SessionFactory close time, that would help. Perhaps we should call it earlier (e.g. at the end of deployment time perhaps if the cache contents are only used at deploy time)?
See https://github.com/raphw/byte-buddy/blob/master/byte-buddy-dep/src/main/java/net/bytebuddy/TypeCache.java + https://github.com/raphw/byte-buddy/blob/master/byte-buddy-dep/src/main/java/net/bytebuddy/TypeCache.java#L167.