gpt4 book ai didi

java - java类元数据放在堆上吗?

转载 作者:太空宇宙 更新时间:2023-11-04 07:32:31 26 4
gpt4 key购买 nike

在Java中,当类加载器加载类文件时,加载的类驻留在哪里?在堆里?我知道对象位于堆中,但是类本身呢?在Java中,即使类也是一个对象,所以我的猜测是它位于堆上?

最佳答案

与加载的类相关的信息(方法、字段等)驻留在 method area 中。 .

Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it. This version of the Java Virtual Machine specification does not mandate the location of the method area or the policies used to manage compiled code.

方法区可能是也可能不是堆的一部分,完全由 JVM 实现决定将其存储在哪里。

Class 对象本身将存储在堆上。

关于java - java类元数据放在堆上吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17474246/

26 4 0