Maxim Kirilov
Maxim Kirilov

Reputation: 2739

Java Thread stack memory allocation and management

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?

Upvotes: 2

Views: 1674

Answers (1)

fge
fge

Reputation: 121702

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).

Upvotes: 3

Related Questions