Click to enter _ more _java thousand ask
1. What are the strategies for memory allocation?
We start with the principle of compiling, different development environment, development language will have different strategies. In general, the program runs with three memory allocation policies: Static, stacked, heap-
Static storage
is the ability to determine the storage space requirements at runtime for each data target at compile time, so that they can be allocated fixed memory space at compile time.
This allocation policy requires that the presence of mutable data structures is not allowed in the program code, and that nested or recursive structures are not allowed because they cause the compiler to be unable to calculate the exact storage space.
Stack-up storage
A stack storage allocation is a dynamic storage allocation that is implemented by a stack-like run stack, as opposed to the allocation of static storage.
In the stack storage scheme, the requirement of the program to the data area is completely unknown at compile time, only when it is run, but it is necessary to know the size of the data area required by the program module in order to allocate its memory when it enters a program module in operation. Like the stacks we know in data structures, stack storage allocations are distributed according to the principles of advanced post-out.
Heap-Storage
Heap storage allocations are specifically responsible for the memory allocation of data structures that are not determined by the storage requirements at compile time or at runtime.
For example, variable-length strings and object instances, the heap consists of large chunks of available or free blocks, and the memory in the heap can be allocated and freed in any order.
2. Java Memory allocation policy
Java's memory allocation is mainly stack-based, as follows:
Learn about the Java memory model look here: What is the Java memory model
See the JVM instance structure here: what is the structure of the JVM instance?
Learn how the JVM manages memory look here: [How the JVM manages memory][4]
[4]:
Java FAQ _07JVM Architecture (003) _ Memory allocation what are the policies