Virtual thread memory leak because TrackingRootContainer keeps threads
Ron Pressler
ron.pressler at oracle.com
Tue Jul 2 18:08:43 UTC 2024
We would eventually like to allow setting tracking option on a per-thread basis, but we need to work out a few details.
> On 1 Jul 2024, at 20:08, Michal Domagala <outsider404 at gmail.com> wrote:
>
> According to https://openjdk.org/jeps/444,
>
> "Unlike platform thread stacks, virtual thread stacks are not GC roots."
>
> But jdk.internal.vm.ThreadContainers.RootContainer.TrackingRootContainer#VTHREADS keeps (hard) references to each virtual thread. Effectively, virtual threads are GC roots.
>
> I described full example here: https://stackoverflow.com/questions/78596905/why-virtual-thread-is-not-garbage-collected-when-not-reachable
>
> The problem was not visible since https://bugs.openjdk.org/browse/JDK-8309406, because before the change, VTHREADS "keep" was not enabled and i guess nobody cares memory leak.
>
> But after the change every JVM is affected.
>
> A workaround for memory leak is set jdk.trackAllThreads=false
>
> Best regards
> Michal Domagala
>
More information about the loom-dev
mailing list