![]() This inner class object has been referenced for a long time, Even if that external class instance object is no longer used, But because the inner class holds the instance object of the outer class, This external class object will not be garbage collected, This can also cause memory leaks. Inner class holds outer class, If the method of an instance object of an external class returns an instance object of an internal class. The singleton pattern, It's similar to a static collection that causes a memory leak, Because of the static characteristics of the singleton, Its life cycle and JVM It's the same life cycle, therefore If a singleton object holds a reference to an external object, Then this external object will not be recycled, Then it will cause memory leak. Briefly, Long life objects hold references to short life objects, Although short-lived objects are no longer used, But because a long-lived object holds its references, it cannot be recycled. If these containers are static, So their life cycle is related to JVM The procedure is consistent, Objects in the container cannot be released until the end of the program, This causes memory leaks. Static collection class, Such as HashMap、LinkedList wait. Java Memory leak in 8 In this case 1- Static collection class Implicit leakage : Keep occupying the memory and not release, Until the end of execution Strictly speaking, this is not a memory leak, Because it finally released, But if the execution time is too long, It can also run out of memory. Happen by accident : It happens in certain circumstances ĭisposable : A memory leak occurs only once It happens all the time : Code with memory leaks will be executed multiple times, Every time you execute, Leak a piece of memory ![]() So, The relationship between memory leak and memory overflow : More memory leaks, It will eventually lead to memory overflow. Let's talk about it more generally, There are three pits in a toilet, There are two people standing in the Maokeng ( Memory leak ), The last pit left, The toilet says the reception pressure is very high, At this time, two people came at once, Pit position ( Memory ) It's not enough, Memory leak becomes memory overflow. When applying for memory, Not enough memory to use In a more popular way, Memory leaks are 【 Don't pull while occupying the Maokeng shi】. The memory is not released after the application, Let's say there are 1024M Of memory, Allocated 512M The memory of has not been recycled, So the only memory available is 512M 了, It seems that part of it has been leaked The relationship between memory leak and memory overflow : ![]() If the object x It also refers to the short life cycle of A、B、C, object A And quoted the object a、b、c, In this way, a large number of useless objects may not be recycled, And then it takes up memory resources, Memory leak, Until memory overflows. So when Y At the end of the life cycle ,X Still quoting Y, Now, The garbage collection period is not to collect objects Y Of Object X Reference object Y,X Life cycle ratio of Y It has a long life cycle īut the actual situation is that many times there are some bad practices ( Or negligence ) It can lead to a long life cycle of an object or even OOM, It can also be called In a broad sense “ Memory leak ”. Strictly speaking, Only objects are no longer used by programs, however GC They can't recycle their situation, Memory leak. Memory leak ( memory leak) The understanding of the So in this case, Due to the different implementation of the code, there will be many kinds of memory leakage problems ( Give Way JVM Error: this object is still in reference, It can't be recycled, Memory leak ). Reachability analysis algorithm to determine whether the object is no longer used, The essence is to judge whether an object is still referenced. 00- To talk about GUI Supplement before tools Add 1: Memory leak Understanding and classification of memory leaks What is a memory leak ( memory leak)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |