Java垃圾收集器的工作方式
Java垃圾收集器的工作方式(中文3200字,英文1700字)
如果你学下过一种因为在堆里分配对象所以开销过大的编程语言,很自然你可能会假定 Java 在堆里为每一样东西(除了 primitives)分配内存资源的机制开销也会很大。不过,事实上垃圾收集器能够深刻影响对象的加速创建。 一开始听起来有些奇怪——存贮空间的释放会影响存贮空间的分配,但是这的确是一些 JVMs 的工作方式,并且这意味着 Java 为堆对象分配存贮空间几乎和别的语言里为栈分配存贮空间一样地快。
How a garbage collector works of Java Language
If you come from a programming language where allocating objects on the heap is expensive, you may naturally assume that Java’s scheme of allocating everything (except primitives) on the heap is also expensive. However, it turns out that the garbage collector can have a significant impact on increasing the speed of object creation. This might sound a bit odd at first—that storage release affects storage allocation—but it’s the way some JVMs work, and it means that allocating storage for heap objects in Java can be nearly as fast as creating storage on the stack in other languages.
[资料来源:http://doc163.com]