<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">I am not sure you can call it a memory leak - you would have the same problem if it was a platform thread - it would be stuck waiting on a queue - and so any references the thread held in its stack would “leak” as well.</div><div class=""><br class=""></div><div class="">Having two different behaviors for platform and virtual threads in this regard would cause a lot of problems with interoperability (switching between thread types).</div><div class=""><br class=""></div><div class="">I don’t think a code author should need to know if their resources are being used by a virtual thread or a platform thread and adjust.</div><div class=""><br class=""></div><div class="">Treating VT threads as GC roots make more sense to me.</div><div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 1, 2024, at 2:08 PM, Michal Domagala <<a href="mailto:outsider404@gmail.com" class="">outsider404@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">According to <a href="https://openjdk.org/jeps/444" class="">https://openjdk.org/jeps/444</a>,<br class=""><br class="">"Unlike platform thread stacks, virtual thread stacks are not GC roots."<br class=""><br class="">But jdk.internal.vm.ThreadContainers.RootContainer.TrackingRootContainer#VTHREADS keeps (hard) references to each virtual thread. Effectively, virtual threads are GC roots.<div class=""><br class=""></div><div class="">I described full example here: <a href="https://stackoverflow.com/questions/78596905/why-virtual-thread-is-not-garbage-collected-when-not-reachable" class="">https://stackoverflow.com/questions/78596905/why-virtual-thread-is-not-garbage-collected-when-not-reachable</a><br class=""><br class="">The problem was not visible since <a href="https://bugs.openjdk.org/browse/JDK-8309406" class="">https://bugs.openjdk.org/browse/JDK-8309406</a>, because before the change, 

VTHREADS "keep" was not enabled and i guess nobody cares memory leak.<br class=""><br class="">But after the change every JVM is affected.</div><div class=""><br class=""></div><div class="">A workaround for memory leak is set <span style="background-color:rgb(244,245,247);color:rgb(23,43,77);font-family:"DejaVu Sans",sans-serif;font-size:14px" class="">jdk.trackAllThreads=false</span></div><div class=""><br class=""></div><div class="">Best regards</div><div class="">Michal Domagala<br class=""><div style="margin: 0px 0px 1.1em; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-stretch: inherit; line-height: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Adjusted", "Segoe UI", "Liberation Sans", sans-serif; font-kerning: inherit; font-feature-settings: inherit; font-size: 15px; vertical-align: baseline; box-sizing: inherit; clear: both; color: rgb(12, 13, 14);" class=""> <br class="webkit-block-placeholder"></div></div></div>
</div></blockquote></div><br class=""></div></body></html>