Skip to content

Classloader not garbage collected due to reference from jackson ObjectMapper #764

@jin-harmoney

Description

@jin-harmoney

Describe the bug

We're building an application on Quarkus and see increasing metaspace memory usage on every live reload. This is caused by the application classloader that is not garbage collected on live-reload.

This seems to be caused by the static ObjectMapper in ObjectMapperWrapper. The ObjectMapper is not loaded by the application classloader, but it does contain references to classes of our application (custom deserializers etc). Hence, it blocks the garbage collection of the application classloader.

To Reproduce

Let me know if I need to provide a reproducer (minimal Quarkus project). Since it's a live-reload issue, I don't think it's possible to add a test for this scenario.

Expected behavior

An elegant solution would be to able to clear all caches used by the ObjectMapper. I raised that question here: FasterXML/jackson-databind#4953.

An alternative solution would be to be able to set the ObjectMapper INSTANCE to null, so it can be garbage collected.

Similar to hibernate-envers, a disintegrate method could be introduced that:

  • Removes any references to ObjectMappers
  • Calls objectMapper.clear() when such a method would be made available in jackson.

Additional context

I described a similar case for hibernate-envers quarkusio/quarkus#46102.

I'm happy to contribute with a PR!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions