Which memory area does GC collect – stack or heap?

JVM defines different memory management mechanisms with stack and heap memory. All GCs clean up the heap memory area by reclaiming the space occupied by unused or unreferenced objects. The GCs don't reclaim space from stack memory.

The stack memory area is used by a current thread for the execution of a method. When the current thread completes the execution of the current method, stack memory is released (without involving a GC collection). The primitives are stored on stack memory.

In a method, the local primitive variables and references to objects (not the actual objects) are stored on the stack. The actual objects are stored on the heap. The local primitive variables and reference variables that are accessible after the execution of a method are defined in the heap memory area. In essence, the following takes place:

  • All objects are stored on the heap.
  • The local object references are stored on the stack; the instance or static object references are stored on the heap.
  • The local primitive variables and their values are stored on the stack. The instance or static primitive variables and their values are stored on the heap.

Let's work with simple use cases where Epsilon GC can help you to improve the performance, memory usage, latency, and throughput of your applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.99.71