gpt4 book ai didi

java - 静态变量存储在java中的哪里?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:52 25 4
gpt4 key购买 nike

<分区>

我想知道静态变量在Java中存放在哪里。
关于 SO 的问题已经很少,例如: where is a static method and a static variable stored in java. In heap or in stack memory

链接指出静态变量存储在堆上。

但以下是 Bill Veners 的一本书(“Inside the Java Virtual Machine”)的全文摘录:

The Method Area
Inside a Java Virtual Machine instance, information about loaded types is stored in a logical area of memory called the method area. When the Java Virtual Machine loads a type, it uses a class loader to locate the appropriate class file. The class loader reads in the class file--a linear stream of binary data-- and passes it to the virtual machine. The virtual machine extracts information about the type from the binary data and stores the information in the method area. Memory for class (static) variables declared in the class is also taken from the method area.

明确指出,当一个类被加载时,静态变量存放在方法区。据我所知,方法区与堆不同。所以这本书与提供的SO链接相矛盾。

有人可以澄清一下困惑吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com