既然 Java 的垃圾回收机制能够自动的回收内存,怎么还会出现内存泄漏的情况呢
伊谢尔伦
伊谢尔伦 2017-04-18 10:49:43
0
10
834

既然 Java 的垃圾回收机制能够自动的回收内存,怎么还会出现内存泄漏的情况呢

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(10)
Ty80

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...

Peter_Zhu

Some objects are actually no longer needed but are always referenced and cannot be recycled

PHPzhong

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 中国那么大,为什么还有人在朝阳区懵逼.

PHPzhong

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[]) {

this.value = value;
this.offset = offset;
this.count = count;

}
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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template