There are two situations of memory overflow: one is stack overflow, such as calling an infinite recursion. There is also a heap overflow, that is, the object that comes out of new is not destroyed immediately, such as new all the time.
Generally speaking, memory leaks in Java refer to the fact that allocated memory that is no longer needed by the program cannot be reclaimed. The garbage collection mechanism determines whether the memory can be recycled through the reachability of the object and the Root object. However, due to programming errors or other reasons, expired object references are still held, and the garbage collector cannot reclaim the relevant space.
There is nothing he can do if he occupies the manhole and does not poop. I recommend reading the blog written by my colleague: http://blog.csdn.net/zhanggan...
For now, things made by humans cannot surpass humans themselves. Java’s GC algorithm was written by humans. However, some people will risk their lives and write code that cannot be recycled by GC
My own understanding, please correct me if I am wrong. In JDK6, a method of String is called subString, which is used to generate a substring. For faster generation, String has a constructor, String(int offset, int count, char value[]) {
} directly points to the original String array. We all know that a new String string in the constant pool will be generated every time. However, this reference causes the original String to not be recycled. Because the value of subString will point to him. This will lead to memory leaks.
The JVM does perform GC by itself without too much interference from programmers. However, due to some incorrect operations, some objects that no longer need to be used still have references, which leads to memory leaks.
Memory resources are limited. Garbage collection only recycles "garbage". Objects that are useful for running your program will not be recycled.
There are two situations of memory overflow: one is stack overflow, such as calling an infinite recursion. There is also a heap overflow, that is, the object that comes out of new is not destroyed immediately, such as new all the time.
Because some poorly written programs will create objects infinitely before the GC mechanism takes effect.
Generally speaking, memory leaks in Java refer to the fact that allocated memory that is no longer needed by the program cannot be reclaimed.
The garbage collection mechanism determines whether the memory can be recycled through the reachability of the object and the Root object. However, due to programming errors or other reasons, expired object references are still held, and the garbage collector cannot reclaim the relevant space.
There is nothing he can do if he occupies the manhole and does not poop.
I recommend reading the blog written by my colleague: http://blog.csdn.net/zhanggan...
Some objects are actually no longer needed but are always referenced and cannot be recycled
For now, things made by humans cannot surpass humans themselves. Java’s GC algorithm was written by humans. However, some people will risk their lives and write code that cannot be recycled by GC
This is just like
中国那么大,为什么还有人在朝阳区懵逼
.My own understanding, please correct me if I am wrong.
In JDK6, a method of String is called subString, which is used to generate a substring. For faster generation, String has a constructor,
String(int offset, int count, char value[]) {
}
directly points to the original String array. We all know that a new String string in the constant pool will be generated every time. However, this reference causes the original String to not be recycled. Because the value of subString will point to him. This will lead to memory leaks.
The JVM does perform GC by itself without too much interference from programmers. However, due to some incorrect operations, some objects that no longer need to be used still have references, which leads to memory leaks.
JVM: Programmers hold on to garbage, which makes me very embarrassed.