Feed like a GC root

I have a question about the roots of GC. I read that one of the roots of GC is the "live thread". What does it mean?

I always had the impression that each thread has its own stack, and the local stack variables are the GC roots for the thread, and now I'm confused. What other types of references to objects that are not in the frame stack or in their own stack are in the stream view?

Another question is whether the collection of the young generation uses the roots of GC, or is it just for basic algorithms?

thanks

Update: Ok, sorry, so for simplicity: I read this short article: yourkit.com/docs/java/help/gc_roots.jsp and there is the option “Thread” as the root of the GC, which means exactly what this thread is gc root What objects does the Thread GC root refer to that its stack does not refer to? Why are these two categories different?

+9
java garbage-collection multithreading gc-roots
source share
3 answers

I read that one of the roots of the GC is Live Thread. What does it mean?

A direct thread is a thread that has been started and not yet completed.

What other types of references to objects that are not in the frame stack or in their own stack have a stream representation?

Missing.

When they say that a (live) stream is a GC root, they mean (essentially) all the values ​​in the frames of the stream stack.

(“Frame Stack” and “native stack” are one and the same.)

... what exactly does it mean that the thread is a GC root?

This means that stream-stream is the root of the GC, and the contents of all live variables in all frames of the stream stack are available.

All this says the same thing.

+3
source share

Imagine that the method with the local new'ed java thread object has disappeared when the method leaves the object (the link goes out of scope and any allocated heap memory is suitable for GC). If you start a stream in the same method, now the lifetime of this stream object and everything that it refers to are also tied to the lifetime of a living / working stream. Until the thread comes out of any memory that is still referenced from the current thread, it is not suitable for the GC, and the thread is called the GC root.

Streams can allocate memory in two different ways through a stack or a heap. The stack store is not GC, but fixed when the current stack stack is unwound. Heap storage is usually allocated when using the “new” in your code (the note new does not always mean that heap storage is in Escape Analysis). A bunch of GC'ed.

A good way to learn more about the roots of the GC is to take a bunch of heaps of your java application and load it into Visual VM or Eclipse MAT, from there you can learn the roots of the GC.

The collection of the younger generation will use GC roots in that objects with GC roots are not suitable for GC, but it would be better to speak in terms of a given algorithm.

0
source share

The JVM shares its threads, some of them are used exclusively for the Garbage collection, some of them are intended for other internal tasks of the JVM, and some fulfill the part provided by the user of the executable file.

In this context, an affordable means is available for user flows. This includes the first thread that should run on public static void main(String[] args) and all threads launched from this thread, except for those that become inaccessible or terminated.

0
source share

All Articles