[External] : Re: Virtual thread memory leak because TrackingRootContainer keeps threads

Ron Pressler ron.pressler at oracle.com
Sat Jul 13 12:57:27 UTC 2024



> On 11 Jul 2024, at 19:40, Michal Domagala <outsider404 at gmail.com> wrote:
> 
> Where is the mistake in my reasoning?
>  

All objects in the heap, including virtual thread stacks, are traversed by the GC. GC *roots*, however, are things that some GCs, G1 in particular, traverse *in a stop-the-world-pause* while they don’t walk non-root objects in a STW pause but concurrently with the application running. Furthermore, roots are kept in memory even if there are no strong references to them, while normal objects are kept only if there are strong references to them.

Virtual threads, unlike platform threads, are regular heap objects rather than roots. This makes a difference to *when* they are scanned by the GC, which has an impact on GC performance, especially as there can be lots and lots of virtual threads. Additionally, *if* there is no strong reference to the virtual thread, the GC may collect it, but I pointed out that usually there is a strong reference that is kept by default for observability purposes, but you can change that option so that such a reference is not kept.

— Ron


More information about the loom-dev mailing list