How does Java manager the memory?
I'm trying to discover how Java manages memory.
I'm learning which part of memory holds static methods and static variables. They said PermGen memory holds static variables and static methods, which is a part of non-heap memory(picture below).
But, from what I've learnt, Java has stack segment to hold local variables, parameters, references, values of non-void function returns... etc, heap segment holds objects and arrays. I've read many many Q&A about this topic and have 2 ways to explain it:
Who can help me to understand this more clearly. If memory is divided into 2 parts: Where's stack ? If memory is divided into 3 parts: Which part holds static methods and static variables ?
I would be grateful to get your help :D Thanks.
Bottom line, there are two parts:
Class
class, that contain static
variables. In the stack, the object typed variables, contain references to objects stored in the heap.
Stack is used for execution of a thread. They contain method specific values that are short-lived and references to other objects in the heap that are getting referred from the method.
Heap memory is used to allocate memory to objects and java runtime environment classes.
More
链接地址: http://www.djcxy.com/p/82868.html上一篇: 有关Java中本地最终变量的问题
下一篇: Java如何管理内存?