Skip to content

Classloader memory leak via JNI global references #13480

@SgtSilvio

Description

@SgtSilvio

Expected behavior

Netty (in this case via reactor-netty) can be used in conjunction with multiple classloaders, allowing classloaders to be properly unloaded if not referenced anymore. (in this case this is important for a gradle plugin)

Actual behavior

When using netty-resolver-dns-native-macos, a classloader and all its classes can not be unloaded even if not referenced anymore as the class io.netty.resolver.dns.macos.DnsResolver is a GC root as a JNI global reference.

This class (and other required classes) are loaded via NETTY_JNI_UTIL_LOAD_CLASS (

NETTY_JNI_UTIL_LOAD_CLASS(env, dnsResolverClass, nettyClassName, done);
) which uses NewGlobalRef (https://github.com/netty/netty-jni-util/blob/8d820fba781882f8a7fe94efb7656d1413ff8bb8/src/main/c/netty_jni_util.h#L45).

Maybe using weak global references instead of global references of the classes is a solution.

Or is there any other solutions how to safely use netty with dynamic classloaders?

Netty version

4.1.94.Final via reactor-netty:1.1.8

JVM version (e.g. java -version)

Any

OS version (e.g. uname -a)

MacOS

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions