问题描述
是一个直接分配到年轻的gen或者old gen或perm gen的静态最终吗? (我想这很可能会在我想象的时间内落入旧有的)。如果它被分配在烫发中,那么当在彼尔姆根的课堂卸载时它会被垃圾收集吗?
一个由静态final
变量引用的对象将根据与其他对象相同的规则。它最有可能分配给年轻一代或老一代(如果它很大并且有其他条件适用)。
该对象将由 new
以某些任意代码执行。 JVM无法知道对象将(最终)分配给 static final
变量。
包含静态变量的帧的空间可能在permGen中分配。当然,这不是一个普通的Java对象。
这取决于permGen是否被垃圾收集。在现代的JVM中,我认为被卸载的类静态引用引用的对象将在相同的GC循环中进行垃圾收集,或者下一个......假设它们无法访问。
无论哪种方式,您都不应编码您的应用程序以依赖任何这些细节。它们是特定于JVM的。
Is a "static final" directly allocated into young gen or old gen or perm gen? (I guess it will most likely land into old gen over the time I suppose.) If it is allocated in the perm gen then, will it be garbage collected when class unloading takes place in Perm Gen ?
An object referenced by a static final
variable will be allocated according to the same rules as any other object. It is most likely to be allocated in the young generation, or in the old generation (if it is large and certain other conditions apply).
The object will be allocated by new
executing in some arbitrary code. The JVM is not in a position to know that the object will (eventually) be assigned to a static final
variable.
The space for the frame containing the static variables is probably allocated in permGen. Of course, this is not a regular Java object.
That depends on whether the permGen is garbage collected. In modern JVMs it is, and I would expect that the objects referenced by an unloaded classes statics would be garbage collected in the same GC cycle, or the next one ... assuming they were unreachable.
Either way, you should not code your application to depend on any of these details. They are JVM specific.
这篇关于何处“静态最终”直接分配到?年轻的gen或老gen或perm gen?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!