memory leaks:Long life-cycle objects that hold references to objects of short lifecycles are likely to have a memory leak, although a short life-cycle object is no longer needed, but because a long-life-cycle object holds its reference and cannot be retracted, this is the scenario of a memory leak in Java.(cannot be used, nor can it be recalled)
Heap Area:1. All objects are stored, each containing a class-corresponding information. (The purpose of class is to get operation instructions) 2.JVM only one heap area (heap) is shared by all threads, and the heap does not hold basic types and object references, only the object itselfStack Area:1. Each thread contains a stack that holds only objects of the underlying data type and references to custom objects (not objects), and objects are stored in the heap 2. The data in each stack (both the original type and the object reference) is private and the other stacks are inaccessible. 3. The stack is divided into 3 parts: the basic type variable area, the execution environment context, the operation instruction area (holds the operation instruction).Method Area:1. Also called the static zone, like the heap, is shared by all threads. The method area contains all class and static variables. 2. The method area contains elements that are always unique throughout the program, such as the class,static variable.when the program runs, it's best to know where the data is stored. It is important to note that there are six places in which data can be stored:1, register. This is the fastest save area because it is located in a different place than all other ways of saving: inside the processor. However, the number of registers is very limited, so the registers are allocated by the compiler as needed. We have no direct control over this, nor can we find any trace of the register in our own program. 2, Stack. resides in the general RAM (random access memory) area. However, the direct support for processing can be obtained through its "stack pointer". If the stack pointer moves down, the new memory is created, and if you move up, the memory is freed. This is a particularly fast, particularly effective way to save data, second only to registers. When you create a program, the Java compiler must know exactly the "length" and "time of existence" of all data saved in the stack. This is because it must generate the appropriate code to move the pointer up and down. This restriction undoubtedly affects the flexibility of the program, so although some Java data is stored in the stack-especially the object handle-the Java object is not placed in it. 3, Heap. A general-purpose memory pool (also in the Ram area) in which Java objects are saved. Unlike stacks: the most fascinating thing about "memory heap" or "heap" is that the compiler does not have to know how much storage to allocate from the heap, or how long the stored data stays in the heap. As a result, there is greater flexibility in storing data with heaps. When you require an object to be created, you only need to use the new command to compile the code that is colliding. When the code is executed, the data is saved automatically in the heap. Of course, to achieve this flexibility, there must be a price: allocating storage space in the heap will take longer than 4, static storage. "Static" here means "in a fixed position". During the run of the program, the data that is stored statically is always waiting to be called. The static keyword can be used to indicate that a particular element of an object is static. However, the Java object itself will never be placed in static storage space. 5, constant storage. The constant value is usually placed directly inside the program code. It is safe to do so. Because they will never change, some constants need to be strictly protected, so consider placing them in read-only memory (ROM). 6, non-RAM storage. If the data is completely independent of a program, the program can still exist when it is not running and outside the control of the program. The two most important examples are "streaming objects" and "fixed objects". For streaming objects, the object becomes a stream of bytes, which is usually sent to another machine, while for fixed objects, the object is saved on disk. Even if the program is aborted, they can still keep their state intact. A particularly useful technique for these types of data stores is that they can exist in other media, and can even be restored to normal, ram-based objects once they are needed.
First of all, there is no static variable in Java concept, you do not believe yourself in the method inside the definition of a static int i =0;java only statically member variables. It belongs to the properties of the class. As for where he put it? Upstairs, the static zone. I don't know if I have this translator. But deep into the JVM is translated into the method area.Virtual Machine Architecture: heap, Method area, local method stack, PC register. The method area holds a template for a class, and the heap is an instance of the class being put. Stacks are generally used to calculate functions. You can find all the books on the bottom of this computer. The data in the stack will not be stored until the function is executed. That's why local variables are the same every time. Even if you add one to him, the next time you execute the function, it will be the same.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Memory allocation