Home > Java > javaTutorial > Detailed introduction to java memory mechanism

Detailed introduction to java memory mechanism

伊谢尔伦
Release: 2017-06-12 13:38:35
Original
1758 people have browsed it

Java divides memory into two types: one is stack memory and the other is heap memory. Some basic types of variables and object reference variables defined in the function are allocated in the stack memory of the function. When a variable is defined in a block of code, Java allocates memory space for the variable in the stack. When the variable exceeds After the scope (for example, call function B in function A, define variable a in function B, the scope of variable a is only function B, after function B runs, variable a will be automatically destroyed. The memory allocated to it will be recycled), Java will automatically release the memory space allocated for the variable, and the memory space can be used for other purposes immediately. The heap memory is used to store the memory array created by new. The memory allocated in the heap is managed by the automatic garbage collector of the Java virtual machine. After generating an array or object in the heap, you can also define a special variable in the stack so that the value of the variable in the stack is equal to the first address of the array or object in the heap memory. The variable in the stack becomes After obtaining the reference variable of the array or object, you can use the variable in the stack to access the array or object in the heap in the program. The reference variable is equivalent to giving a name to the array or object

1. Detailed explanation of Java’s memory mechanism with pictures and texts (with code)

Detailed introduction to java memory mechanism

Introduction: This article The article explains the memory mechanism of Java in detail with pictures and text

2. The memory mechanism of Java is explained in detail (picture and text)

Detailed introduction to java memory mechanism

Introduction: This article mainly introduces the relevant knowledge of Java's memory mechanism, which has a very good reference value. Let's take a look at it with the editor

3. PHP Features Garbage Collection Mechanism 2 - Recycling Cycle

Detailed introduction to java memory mechanism

Introduction: Traditionally, the reference counting memory mechanism used in PHP cannot handle circular reference memory leaks. However, PHP 5.3.0 uses the synchronization algorithm in the article » Concurrent Cycle Collection in Reference Counted Systems to deal with this memory leak problem.

4. Why is it called stack memory? Does this memory mechanism use the principle of stack?

Introduction: This is the encyclopedia's explanation. Java can be replaced by any programming language: C/PHP/Python. It is like we set a variable at the top of the page {code. ..} Is $a = 1 output only at the end? What's going on? Did I understand it wrong? Question: Why is it called stack memory? Is this memory mechanism...

[Related Q&A recommendations]:

php - Why is it called stack memory? Does this memory mechanism use the principle of stack?

The above is the detailed content of Detailed introduction to java memory mechanism. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template