Memory allocations run by Java programs

Source: Internet
Author: User

memory allocation in Java

A: Stack stores local variables
B: Heap Storage for all new
C: Method Area (object-oriented part explained in detail)
D: Local Method Area (System-dependent)
E: Register (CPU use)

Attention:
A: A local variable is defined in the method definition or on a method declaration.
B: The difference between stack memory and heap memory
Stack: When the data is used, it disappears.
Heap: Every new thing that comes out and has an address

Each variable has a default value
Byte,short,int,long 0
float,double 0.0
Char ' \u0000 '
Boolean false
Reference type NULL
After the data is used, it is recycled when the garbage collector is idle.

The concrete difference between stack and heap

Both heaps and stacks are a quick space on memory,
Just the stack is advanced, like a long pipe, only one side has left a hole, to put things inside,
First put in the bottom, then put into the above, want to take out first put in, to first take out after put. You can use it without the programmer's management. The heap is like a vacant space, which can be casually placed, and casually taken. Managed by the programmer, use requests when not required, and require manual release (otherwise a memory overflow may occur).
In addition, the stack executes faster, and the heap executes slower than it does, because he can access it at any time, with size.
The stack memory, which is automatically allocated by the compiler, stores the function's parameter value, the value of the local variable, and so on. It operates in a manner similar to a stack in a data structure. The access order follows the advanced post-out principle. Stack stack: is the program at the start of the program set aside by the work of the memory area,  such as the program's local variables, function calls are taken from the stack, the existence of the need to allocate, do not need to release, by the program compile time to determine the size of the stack space.
Heap: Is the computer spare physical memory and hard disk free space and. But its acquisition is not automatic, it is slower than allocating memory from the stack. Use the stack like we go to a restaurant to eat, just order (send application), pay, and eat (use), eat enough to go, do not bother to cut vegetables, wash vegetables and other preparation work and washing dishes, brush pots and other finishing work, his advantage is fast, but the freedom is small. The use of the heap is like a DIY dish that you like to eat, more trouble, but more in line with their own tastes, and great freedom. The heap space is where the application requests the operating system to allocate its own memory while it is running.

Memory allocations run by Java programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.