Java Memory analysis

Source: Internet
Author: User

In Java, memory management is divided into: stack (stack), heap, datasegment (data segment), Codesegment (code snippet)

Stack: base data type (Byte,short,int,long,char,float,double,boolean), local variable, object's reference address

Heap: Store object instances, new comes out of the place.
Datasegment (data segment): Static variables and string constants

Codesegment (Code snippet): Store code as the name implies

650) this.width=650; "Width=" 547 "height=" 338 "title=" Memory analysis Diagram "style=" width:468px;height:251px;float:left; "alt=" Wkiol1xul-odqninaalojebpj_4167.jpg "src=" Http://s3.51cto.com/wyfs02/M01/71/95/wKioL1XUL-ODQNiNAALOjEBpj_4167.jpg "/>










Instance:

Here's an example of how a Java variable is stored in memory.

Code Segment:arraylistlist[]=new arraylist[2];

arraylist[0]=2;arraylist[1]=3;arraylist[2]=4;

Because list[] is a variable, this is a declaration we put into the stack.

The variables that are instantiated from each subsequent array are then placed in the heap.

The value of a real variable is constant, so it is placed in a constant pool, which is the datasegment.


Java Memory analysis

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.