Home  >  Article  >  Java  >  Detailed introduction to heap memory

Detailed introduction to heap memory

巴扎黑
巴扎黑Original
2017-06-15 14:03:202037browse

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 introduction to java memory mechanism

Detailed introduction to heap memory

##Introduction: Java divides memory into two 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 allocated memory for the variable...

2. Share ten key points of Java heap memory

Detailed introduction to heap memory

Introduction: This article provides a detailed analysis and introduction to the 10 key points of Java heap memory. Friends in need can refer to it

3. Detailed explanation of JavaScript variables, scope and memory

Detailed introduction to heap memory

##Introduction: The basic type values ​​are: undefined, NUll, Boolean, Number and String. These types occupy a fixed size space in the memory. Their values ​​are stored in the stack space and we access them by value. (1) Value type: numerical value, Boolean value, null, undefined. (2) Reference type: object, array, function. If a value of a reference type is assigned, space must be allocated for this value in heap memory. Since the size of such values ​​is not fixed (objects have many properties and methods), they cannot be saved to stack memory. But the memory address size is fixed, so it can...

4.

Things about Java GC (1)

Detailed introduction to heap memory

Introduction: Unlike C language, the allocation and recycling of Java memory (heap memory) are automatically completed by the JVM garbage collector. This feature is very popular. It can help programmers write code better. This article takes the HotSpot virtual machine as an example to talk about Java GC. In the article about Java heap memory in JVM memory, we already know that the Java heap is a memory area shared by all threads, all object instances and arrays

5.

Detailed explanation The storage mechanism of Java's heap memory and stack memory

Detailed introduction to heap memory##Introduction: This article mainly introduces the Java The storage mechanism of heap memory and stack memory, including JVM memory optimization and GC and other related aspects, friends in need can refer to

6.

Java heap memory and stack memory Detailed introduction

Detailed introduction to heap memory

Introduction: This article mainly introduces the relevant information of Java heap memory and stack memory in detail. Here is the introduction of Java heap memory and stack memory. A detailed analysis has been carried out. Friends in need can refer to

7. In-depth JVM analysis of Java’s thread stack

Detailed introduction to heap memory

Introduction: This article mainly introduces the in-depth JVM analysis of Java's thread stack, the application of heap memory and stack principles in Java, etc., which are the focus of in-depth learning of Java. , Friends who need it can refer to

8. Java detailed explanation of garbage collection and object life cycle

Detailed introduction to heap memory

##Introduction: This article mainly introduces Java’s detailed explanation of garbage collection and object life cycle related information. Here is a detailed explanation of heap memory and stack memory and an introduction to the life cycle of JVM. What is needed Friends can refer to

9. Whether static member variables in java are placed in heap memory or stack memory

Introduction: Are static member variables in java placed in heap memory or stack memory?

10. php knowledge point 3-HTTP header-Connection

Introduction:: PHP knowledge point 3-HTTP header-Connection: 1. Overview Some websites will go down after the server has been running for a period of time. There are many reasons that may cause this phenomenon: such as The tomcat heap and non-heap memory settings are insufficient, the program fails to release the memory space, causing memory overflow, or some processes have been running and failed to be released, resulting in a large consumption of cup resources. But in addition to the program itself, it may also be caused by client access (of course, this client also includes search engines such as spider software). If the server and client establish a long link (you can use the "netstat -a" command to view Network access information), which requires ht

[Related Q&A recommendations]:

android - soundpool prompts heap memory overflow

How are complex type variables in JavaScript implemented in memory?

java - Doubts about the equals method in Object and the equals method in String?

java - The centos server CPU is fully occupied by GC tasks, and the program has no memory overflow

javascript - About the js reference type encountered under chorme The problem

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

Statement:
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