Simple memory Analysis in Java program development

Source: Internet
Author: User

The memory is divided into four parts: Stack segment, heap segment, code segment, and data segment;

The new keywords used in our program are stored in heap segment;

Local variables in the program are stored in the stack segment. These local variables are automatically released after the execution of the specific method (the resources in the heap segment need to be processed by the Java Garbage Collector );

The method in the program is in the code segment in the memory, and multiple objects share a code space area;

Static static variables must be placed in the data segment in the memory,

The following is an example of program memory analysis.

Class demo {<br/> private int firistnum; private int secondnum; <br/> Public static int temp = 3; </P> <p> Public demo (INT firstnum, int secondnum) {<br/> This. firstnum = firstnum; <br/> This. secondnum = secondnum; <br/>}</P> <p> public class test {<br/> Public static void main (string [] ARGs) {<br/> demo test = new demo (3, 4); <br/>}< br/>

The following describes the process of memory space allocation.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Step 2 Execution Process

This is the memory space allocation during the execution of the main method. It is very important to analyze the memory for programs with incorrect logic in the future.

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.