Skip to content

[JBMAR-225] Metaspace Memory Leak - SerializableClassRegistry Prevents ClassLoader Garbage Collection #200

@dmlloyd

Description

@dmlloyd

Joshua Swett opened JBMAR-225 and commented

jboss marshalling caches SerailizableClass instances using Java's ClassValue API. The intention here is to be able to weakly cache stuff using the java.lang.Class instance as the cache key while also referencing the java.lang.Class in the cache value (SerializableClass).

Unfortunately, the solution as it stands prevents ClassLoader garbage collection because SeriallzableClassRegistry keeps the ClassValue instance as a static variable which creates a hard reference chain between the ClassLoader and the ClassValue instance:

Some ClassLoader -> SerializableClassRegistry.class -> ClassValue instance

In this case, "Some ClassLoader" is a plugin/module class loader with an augmented class path compared to the System class loader.

The reason "Some ClassLoader" can't be GCed is because there is reference chain starting at the System Class loader that is preventing it that looks something like this:

System ClassLoader -> java.util.HashMap.class (this could be any Serializable class loaded by the System ClassLoader) ->
classValueMap -> SerilizableClass.class (entry in the map) -> "Some ClassLoader" (it loaded SerializableClass)

Affects: 2.0.7.Final

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions