Does Java produce memory leaks? First of all, the answer is yes. Java has a garbage collector, but leaks still exist.
Java memory leaks are not the same as the C + + memory leak concept: the memory leak in C + + means that malloc has some resources, finally no free, memory is not recycled, this is the real memory black hole, and the Java leak means that the existence of Java objects is meaningless to the program, But objects persist throughout the program cycle, which can lead to a memory leak in Java.
To summarize the reasons, there are probably the following aspects:
(1) An object in Java is improperly held by a class that has a long life cycle, which is the main reason for a Java memory leak, where the object is not actively purged in a task, and its host increases the number of references to the object as it works, and it eats more memory, causing a memory leak When a programmer inadvertently forgets to dismiss a reference that an object should not have, the memory leak is still unavoidable.
(2) when the runtime exception, there is no use of finally{} to release certain resources;
(3) The expansion of the range of variables, such as a method of the local variable is defined as a class of variables, so that the life of the variable is longer, it is possible to cause a leak (this and the 1th is a bit like).
Java's memory leak and garbage collection mechanism