netty: Classloader memory leak via JNI global references

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 (https://github.com/netty/netty/blob/79d3fa52dc0ee07ccc1d9c68648b57dc3bafc88e/resolver-dns-native-macos/src/main/c/netty_resolver_dns_macos.c#L186) 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

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 30 (30 by maintainers)

Commits related to this issue

Most upvoted comments

@SgtSilvio yes taking a heap dump is fine…I am also not sure if there is any other way to solve it but I would like to explore this first before making any changes.

Let me do some experiments