简体   繁体   English

通过将Java引用实现为shared_ptr,是否有可能摆脱Java中的垃圾收集器?

[英]Is it possible to get rid of garbage collector in java by implementing java reference as shared_ptr?

将java引用实现为shared_ptr似乎是合理的,并且根本不使用垃圾回收。

It is possible, it is not efficient at all. 有可能,它根本没有效率。

The Oracle's JVM did used reference counting GC in the past, it was slow and not effective. Oracle的JVM过去确实使用了引用计数GC,但是它很慢且无效。 They switched to more modern GC algorithms like generational GC algorithms. 他们改用了更现代的GC算法,例如分代GC算法。

Do not that shared_ptr is acceptable in c++ out of the sheer fact that the vast majority of objects in c++ are allocated in the stack, so the reference counting nature of shared_ptr is barely noticeable. 出于纯粹的事实,即c ++中的绝大多数对象都是在堆栈中分配的,所以不要在C ++中使用shared_ptr,因此shared_ptr的引用计数性质几乎不明显。 On Java, the vast majority of objects are allocated in the heap, so you'd think twice before you start counting them. 在Java上,绝大多数对象都是在堆中分配的,因此在开始计算它们之前,您需要三思而后行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM