Reputation: 2004
I have been going through the garbage collection in java(jdk 6 hot spot JVM).I have few questions which I hope the community will help me to resolve.
What I understand:
1)Heap is divided into
a)Young generation -Eden and Survivor :New objects and arrays are created into the young generation.Minor garbage collection will operate in the young generation. Objects, that are still alive, will be moved from the eden space to the survivor space.
b)Old generation/Tenured Generation:Major collection will move the still alive objects from young generation to old generation.
2)Non Heap is divided into
a)Code Cache
b)Perm generation.
What I want to know:
1)what if survivor gets full..how will minor garbage collection work.
2)When and how is the perm generation garbage collected.
3)Also what happens to the stack..where is it stored or residing?How is its size controlled?
Upvotes: 4
Views: 1916
Reputation: 2004
A stack is the part of the memory. The local automatic variable is created on this stack and method arguments are passed. When a process starts, it get a default stack size which is fixed for each process. In today's operating system, generally, the default stack size is 1 Mb, which is enough for most of the process. Under abnormal condition, the stack limit exceeds. This is known as stack overflow.
Upvotes: 0
Reputation: 86708
The stack size is controlled by being fixed at the point that it is created. If you ever try to use more space than is available on the stack, you will get a "stack overflow" exception.
Upvotes: 0
Reputation: 34813
StringBuilder
variable that you use to build up the return value of a method. You never pass it outside your own method, and you call stringBuilder().toString()
to create a new object at the end of the method. Since Java can tell that the StringBuilder
object won’t outlive the running of the method, it can put it on the stack and deallocate it immediately when the method returns instead of passing it off to the garbage collector.Upvotes: 1