当前位置:网站首页>Form of objects in memory & memory allocation mechanism
Form of objects in memory & memory allocation mechanism
2022-07-27 21:40:00 【Xiao Tang learns to catch babies】
One 、 Object exists in memory in form
1、 First , The memory is divided into three parts : Stack , Pile up , Method area .
- Stack : The reference used to store the object and the method run here .
Be careful :
- When the method runs, it will enter the stack , Immediately after the method is finished .
- After method stack , All object variables in this method will be recycled .
- Pile up : Used to store everything new Objects created .( Address of the object , Object properties, member variables, etc )
Method area : Used to store information about classes ( attribute 、 Method ), And constant pools .
Only constants of string type are stored in the constant pool .( For example, in the heap , The attribute type is of string type , Do not store values directly , But the storage address , This address is the address of the corresponding value in the constant pool .)
- Views on whether the constant pool exists in the heap or in the method area .
JDK1.8 String constant pool and runtime constant pool belong to method area logically , But it's actually in heap memory , Therefore, it can be said that both are stored in the heap , It can also be said that two exist in the method area , This is what is easy to misunderstand .
Two 、 Memory allocation mechanism for classes and objects
First look at the following code
Person p1 = new Person();
p1.age = 10;
p1.name = " Xiao Ming ";
Person p2 = p1;// hold p1 Given to p2 Give Way p2 Point to p1
System.out.println(p2.age);
Excuse me, :p2.age How much is it ? And draw the memory map ( Suppose an address )
Java Memory structure analysis
1) Stack : General storage of basic data types ( local variable )
2) Pile up : Storage objects (Cat cat , Array etc. )
3) Method area : Constant pool ( Constant , Like strings ), Class loading information
边栏推荐
- A new technical director asked me to do an IP territorial function~
- How to realize a good knowledge management system?
- 高并发遇到死锁了,如何搞?
- 美国新宣布制裁的6家中国企业到底是何方神圣?
- 排序(冒泡排序)后面学习持续更新其它排序方法
- 华为成立全球生态发展部:全力推进HMS全球生态建设
- 紫光展锐:2020年将有数十款基于春藤510的5G终端商用
- IDEA常用快捷键及设置方法
- "Geography language" large model Wenxin Ernie geol and its application
- Acwing3715. 最少交换次数(冒泡排序法的模拟思路)
猜你喜欢

腾讯云[HiFlow】| 自动化 -------HiFlow:还在复制粘贴?
![[2022 Niuke multi School Game 2] k-link with bracket sequence I](/img/95/9d6710bfb7b9282b4a06a5f61a1f08.png)
[2022 Niuke multi School Game 2] k-link with bracket sequence I

CBAM学习笔记

"Geography language" large model Wenxin Ernie geol and its application

Design of noise reduction link based on DSP

30 minutes to thoroughly understand the synchronized lock upgrade process

IDEA常用快捷键及设置方法

Chinese and English instructions - human alpha fetoprotein (AFP) ELISA quantitative Kit

C language - Introduction - grammar - pointer (12)

zibbix安装部署
随机推荐
软件测试面试题:设计测试用例时应该考虑哪些方面,即不同的测试用例针对那些方面进行测试?
深入理解递归的方法调用(含实例迷宫问题、汉诺塔、猴子吃桃、斐波拉契、阶乘))
递归/回溯刷题(上)
30 minutes to thoroughly understand the synchronized lock upgrade process
STL源码剖析
成员方法及其传参机制
Some operations about Anaconda (installing software and quickly opening)
【华为HCIE安全考什么科目?华为HCIE安全考什么知识点?】
最高7.5Gbps!全球首款5nm 5G基带骁龙X60发布:支持聚合全部主要频段!
中英文说明书丨 AbFluor 488 细胞凋亡检测试剂盒
看起来是线程池的BUG,但是我认为是源码设计不合理。
疫情之下,手机供应链及线下渠道受阻!销量骤降库存严重!
Microsoft store can't download apps, vs2019 can't download plug-ins solution
Acwing3715. Minimum exchange times (simulation idea of bubble sorting method)
C language - Introduction - grammar - pointer (12)
@The difference between Autowired annotation and @resource annotation
Plato Farm在Elephant Swap上铸造的ePLATO是什么?为何具备高溢价?
美国新宣布制裁的6家中国企业到底是何方神圣?
In addition to "adding machines", in fact, your micro service can be optimized like this
Custom recycleview delete & move animation