2

I am curious to know how java stack threads are managed. Since there is one stack per thread that allocated on a segment of memory specifically requested from the operating system (see Here).

  1. When this memory is released? by garbage collector or by native thread?
  2. How java process signals to the OS that this memory segment isn't used any more?
  3. How this memory affected is the thread was terminated but his corresponding object still has references from other live object?

1 Answer 1

3

When this memory is released? by garbage collector or by native thread?

None. It is released by the OS...

How java process signals to the OS that this memory segment isn't used any more?

... when the thread terminates. The JVM does nothing here but use the native thread API which in turns uses the OS primitives. And...

How this memory affected is the thread was terminated but his corresponding object still has references from other live object?

... this on the other hand is the role of the JVM; of the GC specifically.

Note that creating a Thread (or Runnable or Callable) does not actually create a thread at the OS level; you have to run it for that (using .start() for a Thread, etc etc).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.