类,对象,引用变量在Java中存储在哪里.在堆中还是在堆栈中?堆或堆栈位于何处? [英] Where does class, object, reference variable get stored in Java. In heap or in stack? Where is heap or stack located?

查看:790
本文介绍了类,对象,引用变量在Java中存储在哪里.在堆中还是在堆栈中?堆或堆栈位于何处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道方法的变量存储在堆栈中,而类变量存储在堆中.那么我们创建的类和对象将存储在Java中的什么地方?

I understand that variables of a method are stored in stack and class variables are stored in heap. Then where does the classes and objects we create get stored in Java?

推荐答案

JVM中的运行时数据区域可以如下划分,

Runtime data area in JVM can be divided as below,

  1. 方法区域::已编译类文件的存储区域. (每个JVM实例一个)

  1. Method Area : Storage area for compiled class files. (One per JVM instance)

堆:对象的存储区域. (每个JVM实例一个)

Heap : Storage area for Objects. (One per JVM instance)

Java堆栈:局部变量的存储区域,中间操作的结果. (每个线程一个)

Java stack: Storage area for local variables, results of intermediate operations. (One per thread)

PC寄存器:如果下一条指令是本机方法,则存储要执行的下一条指令的地址,则pc寄存器中的值将不确定. (每个线程一个)

PC Register : Stores the address of the next instruction to be executed if the next instruction is native method then the value in pc register will be undefined. (One per thread)

本机方法堆栈:有助于执行本机方法(用Java以外的语言编写的方法). (每个线程一个)

Native method stacks : Helps in executing native methods (methods written in languages other than Java). (One per thread)

这篇关于类,对象,引用变量在Java中存储在哪里.在堆中还是在堆栈中?堆或堆栈位于何处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆