garbage collection

2018.5.5 Record study

  1. In each part of the memory operation, the three areas of the program counter, virtual machine stack, and local method stack are born with the thread and perish with the thread. The stack frame in the stack is pushed and popped as the method enters and exits

    operation, how much memory is allocated in each stack frame is basically known when the class structure is determined. Therefore, the memory allocation and recovery of these areas is deterministic. At the end of the method and the end of the thread, the memory naturally follows

    Be recycled. 

  2. The Java heap and method areas require memory reclamation: the memory required by multiple implementation classes of an interface is different, and the memory required by multiple branches in a method is also different. We only know when the program is running.

    which objects.

    Method area: Also known as the permanent generation. Garbage collection mainly recycles two parts: abandoned constants and useless classes.

              1) Take the literal in the constant pool as an example: if the string abc has entered the constant pool, and no String object in the system refers to the constant, and no other place refers to the literal,

                  Then it is considered that the string can be recycled,

              2) Useless classes need to meet 3 conditions:

                      (1) All instances of the class have been recycled, that is, there is no instance of the class in the Java heap; 
                      (2) The ClassLoader that loaded the class has been recycled; 
                      (3) The java.lang.Class object corresponding to the class Not being referenced anywhere, the methods of the class cannot be accessed by reflection anywhere.

                      

  3. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325379457&siteId=291194637