先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024b (备注Java)
正文
| — | — |
| 区域1 | 否 |
| 区域2 | 是 |
| 区域3 | 是 |
| 区域4 | 是 |
| 区域5 | 否 |
| 区域6 | 否 |
| 区域7 | 否 |
| 区域8 | 否 |
| 区域9 | 否 |
当需要分配内存时,JVM从空闲列表中检索可用的区域来分配内存
并发安全
当程序在运行时,不是只有一个线程需要创建对象,而是几乎所有的线程都需要创建对象,这时候为对象分配内存区域就会存在并发安全问题,假如线程1的Obj1和线程2的Obj2被分配了同一个内存区域,那程序就乱套了。JVM解决对象内存分配的并发安全问题的方式也有两种:
1. CAS
图源:King老师
从上面的图中可以看出来,当JVM要为一个对象划分一块内存区域时,会使用CAS的方式,即,先读取当前内存地址A的值,经过JVM的预处理,然后将上次读取的值与现在内存地址A的值做比较,如果这两次读到的值相同,则分配成功,也就是Compare and Swap
2. TLAB
使用CAS的方式已经相对较快的(毕竟没有同步块),但是依旧需要进行一次Compare and Swap,还是有性能的损耗。所以JVM中有一个TLAB(Thread Local Allocation Buffer)机制,这是一块存在于Eden中的线程独享的内存区域,由于是线程独享的,所以并不存在并发问题,也就是快。但是TLAB的默认值是Eden的1%,如果对象比较大,还是得通过CAS的方式在堆中分配(不一定会分配在Eden中!大对象的话,会直接分配到年老代)
对象的内存布局
对象的内存布局大体如下:
#mermaid-svg-lP62qH9z9VDZ3lvB .label{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);fill:#333;color:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .label text{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .node rect,#mermaid-svg-lP62qH9z9VDZ3lvB .node circle,#mermaid-svg-lP62qH9z9VDZ3lvB .node ellipse,#mermaid-svg-lP62qH9z9VDZ3lvB .node polygon,#mermaid-svg-lP62qH9z9VDZ3lvB .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-lP62qH9z9VDZ3lvB .node .label{text-align:center;fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .node.clickable{cursor:pointer}#mermaid-svg-lP62qH9z9VDZ3lvB .arrowheadPath{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-lP62qH9z9VDZ3lvB .flowchart-link{stroke:#333;fill:none}#mermaid-svg-lP62qH9z9VDZ3lvB .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-lP62qH9z9VDZ3lvB .edgeLabel rect{opacity:0.9}#mermaid-svg-lP62qH9z9VDZ3lvB .edgeLabel span{color:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-lP62qH9z9VDZ3lvB .cluster text{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-lP62qH9z9VDZ3lvB .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-lP62qH9z9VDZ3lvB text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-lP62qH9z9VDZ3lvB .actor-line{stroke:grey}#mermaid-svg-lP62qH9z9VDZ3lvB .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-lP62qH9z9VDZ3lvB #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .sequenceNumber{fill:#fff}#mermaid-svg-lP62qH9z9VDZ3lvB #sequencenumber{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB #crosshead path{fill:#333;stroke:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .messageText{fill:#333;stroke:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-lP62qH9z9VDZ3lvB .labelText,#mermaid-svg-lP62qH9z9VDZ3lvB .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-lP62qH9z9VDZ3lvB .loopText,#mermaid-svg-lP62qH9z9VDZ3lvB .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-lP62qH9z9VDZ3lvB .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-lP62qH9z9VDZ3lvB .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-lP62qH9z9VDZ3lvB .noteText,#mermaid-svg-lP62qH9z9VDZ3lvB .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-lP62qH9z9VDZ3lvB .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-lP62qH9z9VDZ3lvB .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-lP62qH9z9VDZ3lvB .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-lP62qH9z9VDZ3lvB .mermaid-main-font{font-family:“trebuchet ms”, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .section{stroke:none;opacity:0.2}#mermaid-svg-lP62qH9z9VDZ3lvB .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-lP62qH9z9VDZ3lvB .section2{fill:#fff400}#mermaid-svg-lP62qH9z9VDZ3lvB .section1,#mermaid-svg-lP62qH9z9VDZ3lvB .section3{fill:#fff;opacity:0.2}#mermaid-svg-lP62qH9z9VDZ3lvB .sectionTitle0{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .sectionTitle1{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .sectionTitle2{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .sectionTitle3{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-lP62qH9z9VDZ3lvB .grid .tick text{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .grid path{stroke-width:0}#mermaid-svg-lP62qH9z9VDZ3lvB .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-lP62qH9z9VDZ3lvB .task{stroke-width:2}#mermaid-svg-lP62qH9z9VDZ3lvB .taskText{text-anchor:middle;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .taskText:not([font-size]){font-size:11px}#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-lP62qH9z9VDZ3lvB .task.clickable{cursor:pointer}#mermaid-svg-lP62qH9z9VDZ3lvB .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-lP62qH9z9VDZ3lvB .taskText0,#mermaid-svg-lP62qH9z9VDZ3lvB .taskText1,#mermaid-svg-lP62qH9z9VDZ3lvB .taskText2,#mermaid-svg-lP62qH9z9VDZ3lvB .taskText3{fill:#fff}#mermaid-svg-lP62qH9z9VDZ3lvB .task0,#mermaid-svg-lP62qH9z9VDZ3lvB .task1,#mermaid-svg-lP62qH9z9VDZ3lvB .task2,#mermaid-svg-lP62qH9z9VDZ3lvB .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutside0,#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutside2{fill:#000}#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutside1,#mermaid-svg-lP62qH9z9VDZ3lvB .taskTextOutside3{fill:#000}#mermaid-svg-lP62qH9z9VDZ3lvB .active0,#mermaid-svg-lP62qH9z9VDZ3lvB .active1,#mermaid-svg-lP62qH9z9VDZ3lvB .active2,#mermaid-svg-lP62qH9z9VDZ3lvB .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-lP62qH9z9VDZ3lvB .activeText0,#mermaid-svg-lP62qH9z9VDZ3lvB .activeText1,#mermaid-svg-lP62qH9z9VDZ3lvB .activeText2,#mermaid-svg-lP62qH9z9VDZ3lvB .activeText3{fill:#000 !important}#mermaid-svg-lP62qH9z9VDZ3lvB .done0,#mermaid-svg-lP62qH9z9VDZ3lvB .done1,#mermaid-svg-lP62qH9z9VDZ3lvB .done2,#mermaid-svg-lP62qH9z9VDZ3lvB .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-lP62qH9z9VDZ3lvB .doneText0,#mermaid-svg-lP62qH9z9VDZ3lvB .doneText1,#mermaid-svg-lP62qH9z9VDZ3lvB .doneText2,#mermaid-svg-lP62qH9z9VDZ3lvB .doneText3{fill:#000 !important}#mermaid-svg-lP62qH9z9VDZ3lvB .crit0,#mermaid-svg-lP62qH9z9VDZ3lvB .crit1,#mermaid-svg-lP62qH9z9VDZ3lvB .crit2,#mermaid-svg-lP62qH9z9VDZ3lvB .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-lP62qH9z9VDZ3lvB .activeCrit0,#mermaid-svg-lP62qH9z9VDZ3lvB .activeCrit1,#mermaid-svg-lP62qH9z9VDZ3lvB .activeCrit2,#mermaid-svg-lP62qH9z9VDZ3lvB .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-lP62qH9z9VDZ3lvB .doneCrit0,#mermaid-svg-lP62qH9z9VDZ3lvB .doneCrit1,#mermaid-svg-lP62qH9z9VDZ3lvB .doneCrit2,#mermaid-svg-lP62qH9z9VDZ3lvB .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-lP62qH9z9VDZ3lvB .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-lP62qH9z9VDZ3lvB .milestoneText{font-style:italic}#mermaid-svg-lP62qH9z9VDZ3lvB .doneCritText0,#mermaid-svg-lP62qH9z9VDZ3lvB .doneCritText1,#mermaid-svg-lP62qH9z9VDZ3lvB .doneCritText2,#mermaid-svg-lP62qH9z9VDZ3lvB .doneCritText3{fill:#000 !important}#mermaid-svg-lP62qH9z9VDZ3lvB .activeCritText0,#mermaid-svg-lP62qH9z9VDZ3lvB .activeCritText1,#mermaid-svg-lP62qH9z9VDZ3lvB .activeCritText2,#mermaid-svg-lP62qH9z9VDZ3lvB .activeCritText3{fill:#000 !important}#mermaid-svg-lP62qH9z9VDZ3lvB .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB g.classGroup text{fill:#9370db;stroke:none;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:10px}#mermaid-svg-lP62qH9z9VDZ3lvB g.classGroup text .title{font-weight:bolder}#mermaid-svg-lP62qH9z9VDZ3lvB g.clickable{cursor:pointer}#mermaid-svg-lP62qH9z9VDZ3lvB g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-lP62qH9z9VDZ3lvB g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-lP62qH9z9VDZ3lvB .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-lP62qH9z9VDZ3lvB .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-lP62qH9z9VDZ3lvB .dashed-line{stroke-dasharray:3}#mermaid-svg-lP62qH9z9VDZ3lvB #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB .commit-id,#mermaid-svg-lP62qH9z9VDZ3lvB .commit-msg,#mermaid-svg-lP62qH9z9VDZ3lvB .branch-label{fill:lightgrey;color:lightgrey;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .slice{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-lP62qH9z9VDZ3lvB g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-lP62qH9z9VDZ3lvB g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-lP62qH9z9VDZ3lvB g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-lP62qH9z9VDZ3lvB .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-lP62qH9z9VDZ3lvB .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-lP62qH9z9VDZ3lvB .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-lP62qH9z9VDZ3lvB .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-lP62qH9z9VDZ3lvB .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-lP62qH9z9VDZ3lvB .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-lP62qH9z9VDZ3lvB .edgeLabel text{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-lP62qH9z9VDZ3lvB .node circle.state-start{fill:black;stroke:black}#mermaid-svg-lP62qH9z9VDZ3lvB .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-lP62qH9z9VDZ3lvB #statediagram-barbEnd{fill:#9370db}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-state .divider{stroke:#9370db}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-lP62qH9z9VDZ3lvB .note-edge{stroke-dasharray:5}#mermaid-svg-lP62qH9z9VDZ3lvB .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{–mermaid-font-family: ‘“trebuchet ms”, verdana, arial’;–mermaid-font-family: “Comic Sans MS”, “Comic Sans”, cursive}#mermaid-svg-lP62qH9z9VDZ3lvB .error-icon{fill:#522}#mermaid-svg-lP62qH9z9VDZ3lvB .error-text{fill:#522;stroke:#522}#mermaid-svg-lP62qH9z9VDZ3lvB .edge-thickness-normal{stroke-width:2px}#mermaid-svg-lP62qH9z9VDZ3lvB .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-lP62qH9z9VDZ3lvB .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-lP62qH9z9VDZ3lvB .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-lP62qH9z9VDZ3lvB .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-lP62qH9z9VDZ3lvB .marker{fill:#333}#mermaid-svg-lP62qH9z9VDZ3lvB .marker.cross{stroke:#333} :root { --mermaid-font-family: “trebuchet ms”, verdana, arial;} #mermaid-svg-lP62qH9z9VDZ3lvB { color: rgba(0, 0, 0, 0.75); font: ; }
不一定
如果是数组
对象
对象头
实例数据
对齐填充
对象类型指针
数组长度
mark word
哈希码
对象分代年龄
锁状态标识
线程持有的锁
偏向线程id
偏向时间戳
在一个对象中,一定会有的是对象头和实例数据,但是不一定会有对齐填充。因为虚拟机规范中规范每个对象的大小都必须是8byte的整数倍,如果当前对象的实例数据+对象头的大小不是8字节的整数倍,那就需要对齐填充,将这个对象填充够8字节的整数倍。
整理一下对象的内存布局
-
对象头
-
对象运行时数据(mark word)
-
哈希码
-
GC分代年龄
-
锁状态标识
-
线程持有的锁
-
偏向线程id
-
偏向时间戳
-
对象的类型指针
-
如果对象是数组类型,那还会存储数组的长度
-
实例数据
-
对齐填充(不是100%有)
=======================================================================
对象访问定位有两种方式:
使用句柄池的方式访问对象的意思是,栈帧中局部变量中的引用指向的句柄池中的某个句柄,然后这个句柄再指向堆中的某个对象,大概就是这样:
#mermaid-svg-v2DJOEz8L0Li2B8d .label{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);fill:#333;color:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .label text{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .node rect,#mermaid-svg-v2DJOEz8L0Li2B8d .node circle,#mermaid-svg-v2DJOEz8L0Li2B8d .node ellipse,#mermaid-svg-v2DJOEz8L0Li2B8d .node polygon,#mermaid-svg-v2DJOEz8L0Li2B8d .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-v2DJOEz8L0Li2B8d .node .label{text-align:center;fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .node.clickable{cursor:pointer}#mermaid-svg-v2DJOEz8L0Li2B8d .arrowheadPath{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-v2DJOEz8L0Li2B8d .flowchart-link{stroke:#333;fill:none}#mermaid-svg-v2DJOEz8L0Li2B8d .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-v2DJOEz8L0Li2B8d .edgeLabel rect{opacity:0.9}#mermaid-svg-v2DJOEz8L0Li2B8d .edgeLabel span{color:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-v2DJOEz8L0Li2B8d .cluster text{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-v2DJOEz8L0Li2B8d .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-v2DJOEz8L0Li2B8d text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-v2DJOEz8L0Li2B8d .actor-line{stroke:grey}#mermaid-svg-v2DJOEz8L0Li2B8d .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-v2DJOEz8L0Li2B8d #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .sequenceNumber{fill:#fff}#mermaid-svg-v2DJOEz8L0Li2B8d #sequencenumber{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d #crosshead path{fill:#333;stroke:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .messageText{fill:#333;stroke:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-v2DJOEz8L0Li2B8d .labelText,#mermaid-svg-v2DJOEz8L0Li2B8d .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-v2DJOEz8L0Li2B8d .loopText,#mermaid-svg-v2DJOEz8L0Li2B8d .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-v2DJOEz8L0Li2B8d .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-v2DJOEz8L0Li2B8d .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-v2DJOEz8L0Li2B8d .noteText,#mermaid-svg-v2DJOEz8L0Li2B8d .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-v2DJOEz8L0Li2B8d .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-v2DJOEz8L0Li2B8d .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-v2DJOEz8L0Li2B8d .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-v2DJOEz8L0Li2B8d .mermaid-main-font{font-family:“trebuchet ms”, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .section{stroke:none;opacity:0.2}#mermaid-svg-v2DJOEz8L0Li2B8d .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-v2DJOEz8L0Li2B8d .section2{fill:#fff400}#mermaid-svg-v2DJOEz8L0Li2B8d .section1,#mermaid-svg-v2DJOEz8L0Li2B8d .section3{fill:#fff;opacity:0.2}#mermaid-svg-v2DJOEz8L0Li2B8d .sectionTitle0{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .sectionTitle1{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .sectionTitle2{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .sectionTitle3{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-v2DJOEz8L0Li2B8d .grid .tick text{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .grid path{stroke-width:0}#mermaid-svg-v2DJOEz8L0Li2B8d .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-v2DJOEz8L0Li2B8d .task{stroke-width:2}#mermaid-svg-v2DJOEz8L0Li2B8d .taskText{text-anchor:middle;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .taskText:not([font-size]){font-size:11px}#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-v2DJOEz8L0Li2B8d .task.clickable{cursor:pointer}#mermaid-svg-v2DJOEz8L0Li2B8d .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-v2DJOEz8L0Li2B8d .taskText0,#mermaid-svg-v2DJOEz8L0Li2B8d .taskText1,#mermaid-svg-v2DJOEz8L0Li2B8d .taskText2,#mermaid-svg-v2DJOEz8L0Li2B8d .taskText3{fill:#fff}#mermaid-svg-v2DJOEz8L0Li2B8d .task0,#mermaid-svg-v2DJOEz8L0Li2B8d .task1,#mermaid-svg-v2DJOEz8L0Li2B8d .task2,#mermaid-svg-v2DJOEz8L0Li2B8d .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutside0,#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutside2{fill:#000}#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutside1,#mermaid-svg-v2DJOEz8L0Li2B8d .taskTextOutside3{fill:#000}#mermaid-svg-v2DJOEz8L0Li2B8d .active0,#mermaid-svg-v2DJOEz8L0Li2B8d .active1,#mermaid-svg-v2DJOEz8L0Li2B8d .active2,#mermaid-svg-v2DJOEz8L0Li2B8d .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-v2DJOEz8L0Li2B8d .activeText0,#mermaid-svg-v2DJOEz8L0Li2B8d .activeText1,#mermaid-svg-v2DJOEz8L0Li2B8d .activeText2,#mermaid-svg-v2DJOEz8L0Li2B8d .activeText3{fill:#000 !important}#mermaid-svg-v2DJOEz8L0Li2B8d .done0,#mermaid-svg-v2DJOEz8L0Li2B8d .done1,#mermaid-svg-v2DJOEz8L0Li2B8d .done2,#mermaid-svg-v2DJOEz8L0Li2B8d .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-v2DJOEz8L0Li2B8d .doneText0,#mermaid-svg-v2DJOEz8L0Li2B8d .doneText1,#mermaid-svg-v2DJOEz8L0Li2B8d .doneText2,#mermaid-svg-v2DJOEz8L0Li2B8d .doneText3{fill:#000 !important}#mermaid-svg-v2DJOEz8L0Li2B8d .crit0,#mermaid-svg-v2DJOEz8L0Li2B8d .crit1,#mermaid-svg-v2DJOEz8L0Li2B8d .crit2,#mermaid-svg-v2DJOEz8L0Li2B8d .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-v2DJOEz8L0Li2B8d .activeCrit0,#mermaid-svg-v2DJOEz8L0Li2B8d .activeCrit1,#mermaid-svg-v2DJOEz8L0Li2B8d .activeCrit2,#mermaid-svg-v2DJOEz8L0Li2B8d .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-v2DJOEz8L0Li2B8d .doneCrit0,#mermaid-svg-v2DJOEz8L0Li2B8d .doneCrit1,#mermaid-svg-v2DJOEz8L0Li2B8d .doneCrit2,#mermaid-svg-v2DJOEz8L0Li2B8d .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-v2DJOEz8L0Li2B8d .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-v2DJOEz8L0Li2B8d .milestoneText{font-style:italic}#mermaid-svg-v2DJOEz8L0Li2B8d .doneCritText0,#mermaid-svg-v2DJOEz8L0Li2B8d .doneCritText1,#mermaid-svg-v2DJOEz8L0Li2B8d .doneCritText2,#mermaid-svg-v2DJOEz8L0Li2B8d .doneCritText3{fill:#000 !important}#mermaid-svg-v2DJOEz8L0Li2B8d .activeCritText0,#mermaid-svg-v2DJOEz8L0Li2B8d .activeCritText1,#mermaid-svg-v2DJOEz8L0Li2B8d .activeCritText2,#mermaid-svg-v2DJOEz8L0Li2B8d .activeCritText3{fill:#000 !important}#mermaid-svg-v2DJOEz8L0Li2B8d .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d g.classGroup text{fill:#9370db;stroke:none;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:10px}#mermaid-svg-v2DJOEz8L0Li2B8d g.classGroup text .title{font-weight:bolder}#mermaid-svg-v2DJOEz8L0Li2B8d g.clickable{cursor:pointer}#mermaid-svg-v2DJOEz8L0Li2B8d g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-v2DJOEz8L0Li2B8d g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-v2DJOEz8L0Li2B8d .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-v2DJOEz8L0Li2B8d .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-v2DJOEz8L0Li2B8d .dashed-line{stroke-dasharray:3}#mermaid-svg-v2DJOEz8L0Li2B8d #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d .commit-id,#mermaid-svg-v2DJOEz8L0Li2B8d .commit-msg,#mermaid-svg-v2DJOEz8L0Li2B8d .branch-label{fill:lightgrey;color:lightgrey;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .slice{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-v2DJOEz8L0Li2B8d g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-v2DJOEz8L0Li2B8d g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-v2DJOEz8L0Li2B8d g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-v2DJOEz8L0Li2B8d .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-v2DJOEz8L0Li2B8d .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-v2DJOEz8L0Li2B8d .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-v2DJOEz8L0Li2B8d .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-v2DJOEz8L0Li2B8d .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-v2DJOEz8L0Li2B8d .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-v2DJOEz8L0Li2B8d .edgeLabel text{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-v2DJOEz8L0Li2B8d .node circle.state-start{fill:black;stroke:black}#mermaid-svg-v2DJOEz8L0Li2B8d .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-v2DJOEz8L0Li2B8d #statediagram-barbEnd{fill:#9370db}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-state .divider{stroke:#9370db}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-v2DJOEz8L0Li2B8d .note-edge{stroke-dasharray:5}#mermaid-svg-v2DJOEz8L0Li2B8d .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{–mermaid-font-family: ‘“trebuchet ms”, verdana, arial’;–mermaid-font-family: “Comic Sans MS”, “Comic Sans”, cursive}#mermaid-svg-v2DJOEz8L0Li2B8d .error-icon{fill:#522}#mermaid-svg-v2DJOEz8L0Li2B8d .error-text{fill:#522;stroke:#522}#mermaid-svg-v2DJOEz8L0Li2B8d .edge-thickness-normal{stroke-width:2px}#mermaid-svg-v2DJOEz8L0Li2B8d .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-v2DJOEz8L0Li2B8d .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-v2DJOEz8L0Li2B8d .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-v2DJOEz8L0Li2B8d .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-v2DJOEz8L0Li2B8d .marker{fill:#333}#mermaid-svg-v2DJOEz8L0Li2B8d .marker.cross{stroke:#333} :root { --mermaid-font-family: “trebuchet ms”, verdana, arial;} #mermaid-svg-v2DJOEz8L0Li2B8d { color: rgba(0, 0, 0, 0.75); font: ; }
局部变量表中的引用
句柄A
对象1
优点:这样做的优点是局部变量表中的引用是指向句柄池中的句柄的,当对象发生变化(被回收或被移动到其他的内存地址)时,只需要更新句柄池对对象的引用即可,这样可以保证程序的稳定
缺点:由于引入了句柄池,导致了对象的访问多了一次处理从而降低了访问速度
引申:句柄池在堆里
直接指针就是这样的:中间没有句柄池,局部变量表中的引用直接指向堆中的内存对象
#mermaid-svg-fJN3u2f4WNIr4ota .label{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);fill:#333;color:#333}#mermaid-svg-fJN3u2f4WNIr4ota .label text{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .node rect,#mermaid-svg-fJN3u2f4WNIr4ota .node circle,#mermaid-svg-fJN3u2f4WNIr4ota .node ellipse,#mermaid-svg-fJN3u2f4WNIr4ota .node polygon,#mermaid-svg-fJN3u2f4WNIr4ota .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-fJN3u2f4WNIr4ota .node .label{text-align:center;fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .node.clickable{cursor:pointer}#mermaid-svg-fJN3u2f4WNIr4ota .arrowheadPath{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-fJN3u2f4WNIr4ota .flowchart-link{stroke:#333;fill:none}#mermaid-svg-fJN3u2f4WNIr4ota .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-fJN3u2f4WNIr4ota .edgeLabel rect{opacity:0.9}#mermaid-svg-fJN3u2f4WNIr4ota .edgeLabel span{color:#333}#mermaid-svg-fJN3u2f4WNIr4ota .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-fJN3u2f4WNIr4ota .cluster text{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-fJN3u2f4WNIr4ota .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-fJN3u2f4WNIr4ota text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-fJN3u2f4WNIr4ota .actor-line{stroke:grey}#mermaid-svg-fJN3u2f4WNIr4ota .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-fJN3u2f4WNIr4ota .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-fJN3u2f4WNIr4ota #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-fJN3u2f4WNIr4ota .sequenceNumber{fill:#fff}#mermaid-svg-fJN3u2f4WNIr4ota #sequencenumber{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota #crosshead path{fill:#333;stroke:#333}#mermaid-svg-fJN3u2f4WNIr4ota .messageText{fill:#333;stroke:#333}#mermaid-svg-fJN3u2f4WNIr4ota .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-fJN3u2f4WNIr4ota .labelText,#mermaid-svg-fJN3u2f4WNIr4ota .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-fJN3u2f4WNIr4ota .loopText,#mermaid-svg-fJN3u2f4WNIr4ota .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-fJN3u2f4WNIr4ota .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-fJN3u2f4WNIr4ota .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-fJN3u2f4WNIr4ota .noteText,#mermaid-svg-fJN3u2f4WNIr4ota .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-fJN3u2f4WNIr4ota .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-fJN3u2f4WNIr4ota .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-fJN3u2f4WNIr4ota .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-fJN3u2f4WNIr4ota .mermaid-main-font{font-family:“trebuchet ms”, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .section{stroke:none;opacity:0.2}#mermaid-svg-fJN3u2f4WNIr4ota .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-fJN3u2f4WNIr4ota .section2{fill:#fff400}#mermaid-svg-fJN3u2f4WNIr4ota .section1,#mermaid-svg-fJN3u2f4WNIr4ota .section3{fill:#fff;opacity:0.2}#mermaid-svg-fJN3u2f4WNIr4ota .sectionTitle0{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .sectionTitle1{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .sectionTitle2{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .sectionTitle3{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-fJN3u2f4WNIr4ota .grid .tick text{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .grid path{stroke-width:0}#mermaid-svg-fJN3u2f4WNIr4ota .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-fJN3u2f4WNIr4ota .task{stroke-width:2}#mermaid-svg-fJN3u2f4WNIr4ota .taskText{text-anchor:middle;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .taskText:not([font-size]){font-size:11px}#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-fJN3u2f4WNIr4ota .task.clickable{cursor:pointer}#mermaid-svg-fJN3u2f4WNIr4ota .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-fJN3u2f4WNIr4ota .taskText0,#mermaid-svg-fJN3u2f4WNIr4ota .taskText1,#mermaid-svg-fJN3u2f4WNIr4ota .taskText2,#mermaid-svg-fJN3u2f4WNIr4ota .taskText3{fill:#fff}#mermaid-svg-fJN3u2f4WNIr4ota .task0,#mermaid-svg-fJN3u2f4WNIr4ota .task1,#mermaid-svg-fJN3u2f4WNIr4ota .task2,#mermaid-svg-fJN3u2f4WNIr4ota .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutside0,#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutside2{fill:#000}#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutside1,#mermaid-svg-fJN3u2f4WNIr4ota .taskTextOutside3{fill:#000}#mermaid-svg-fJN3u2f4WNIr4ota .active0,#mermaid-svg-fJN3u2f4WNIr4ota .active1,#mermaid-svg-fJN3u2f4WNIr4ota .active2,#mermaid-svg-fJN3u2f4WNIr4ota .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-fJN3u2f4WNIr4ota .activeText0,#mermaid-svg-fJN3u2f4WNIr4ota .activeText1,#mermaid-svg-fJN3u2f4WNIr4ota .activeText2,#mermaid-svg-fJN3u2f4WNIr4ota .activeText3{fill:#000 !important}#mermaid-svg-fJN3u2f4WNIr4ota .done0,#mermaid-svg-fJN3u2f4WNIr4ota .done1,#mermaid-svg-fJN3u2f4WNIr4ota .done2,#mermaid-svg-fJN3u2f4WNIr4ota .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-fJN3u2f4WNIr4ota .doneText0,#mermaid-svg-fJN3u2f4WNIr4ota .doneText1,#mermaid-svg-fJN3u2f4WNIr4ota .doneText2,#mermaid-svg-fJN3u2f4WNIr4ota .doneText3{fill:#000 !important}#mermaid-svg-fJN3u2f4WNIr4ota .crit0,#mermaid-svg-fJN3u2f4WNIr4ota .crit1,#mermaid-svg-fJN3u2f4WNIr4ota .crit2,#mermaid-svg-fJN3u2f4WNIr4ota .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-fJN3u2f4WNIr4ota .activeCrit0,#mermaid-svg-fJN3u2f4WNIr4ota .activeCrit1,#mermaid-svg-fJN3u2f4WNIr4ota .activeCrit2,#mermaid-svg-fJN3u2f4WNIr4ota .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-fJN3u2f4WNIr4ota .doneCrit0,#mermaid-svg-fJN3u2f4WNIr4ota .doneCrit1,#mermaid-svg-fJN3u2f4WNIr4ota .doneCrit2,#mermaid-svg-fJN3u2f4WNIr4ota .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-fJN3u2f4WNIr4ota .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-fJN3u2f4WNIr4ota .milestoneText{font-style:italic}#mermaid-svg-fJN3u2f4WNIr4ota .doneCritText0,#mermaid-svg-fJN3u2f4WNIr4ota .doneCritText1,#mermaid-svg-fJN3u2f4WNIr4ota .doneCritText2,#mermaid-svg-fJN3u2f4WNIr4ota .doneCritText3{fill:#000 !important}#mermaid-svg-fJN3u2f4WNIr4ota .activeCritText0,#mermaid-svg-fJN3u2f4WNIr4ota .activeCritText1,#mermaid-svg-fJN3u2f4WNIr4ota .activeCritText2,#mermaid-svg-fJN3u2f4WNIr4ota .activeCritText3{fill:#000 !important}#mermaid-svg-fJN3u2f4WNIr4ota .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota g.classGroup text{fill:#9370db;stroke:none;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:10px}#mermaid-svg-fJN3u2f4WNIr4ota g.classGroup text .title{font-weight:bolder}#mermaid-svg-fJN3u2f4WNIr4ota g.clickable{cursor:pointer}#mermaid-svg-fJN3u2f4WNIr4ota g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-fJN3u2f4WNIr4ota g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-fJN3u2f4WNIr4ota .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-fJN3u2f4WNIr4ota .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-fJN3u2f4WNIr4ota .dashed-line{stroke-dasharray:3}#mermaid-svg-fJN3u2f4WNIr4ota #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota .commit-id,#mermaid-svg-fJN3u2f4WNIr4ota .commit-msg,#mermaid-svg-fJN3u2f4WNIr4ota .branch-label{fill:lightgrey;color:lightgrey;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .slice{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-fJN3u2f4WNIr4ota g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-fJN3u2f4WNIr4ota g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-fJN3u2f4WNIr4ota g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-fJN3u2f4WNIr4ota .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-fJN3u2f4WNIr4ota .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-fJN3u2f4WNIr4ota .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-fJN3u2f4WNIr4ota .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-fJN3u2f4WNIr4ota .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-fJN3u2f4WNIr4ota .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-fJN3u2f4WNIr4ota .edgeLabel text{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-fJN3u2f4WNIr4ota .node circle.state-start{fill:black;stroke:black}#mermaid-svg-fJN3u2f4WNIr4ota .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-fJN3u2f4WNIr4ota #statediagram-barbEnd{fill:#9370db}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-state .divider{stroke:#9370db}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-fJN3u2f4WNIr4ota .note-edge{stroke-dasharray:5}#mermaid-svg-fJN3u2f4WNIr4ota .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{–mermaid-font-family: ‘“trebuchet ms”, verdana, arial’;–mermaid-font-family: “Comic Sans MS”, “Comic Sans”, cursive}#mermaid-svg-fJN3u2f4WNIr4ota .error-icon{fill:#522}#mermaid-svg-fJN3u2f4WNIr4ota .error-text{fill:#522;stroke:#522}#mermaid-svg-fJN3u2f4WNIr4ota .edge-thickness-normal{stroke-width:2px}#mermaid-svg-fJN3u2f4WNIr4ota .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-fJN3u2f4WNIr4ota .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-fJN3u2f4WNIr4ota .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-fJN3u2f4WNIr4ota .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-fJN3u2f4WNIr4ota .marker{fill:#333}#mermaid-svg-fJN3u2f4WNIr4ota .marker.cross{stroke:#333} :root { --mermaid-font-family: “trebuchet ms”, verdana, arial;} #mermaid-svg-fJN3u2f4WNIr4ota { color: rgba(0, 0, 0, 0.75); font: ; }
局部变量表中的引用
对象1
优点:没有句柄池,也就没有中间过程,对象的访问速度提升了
缺点:实现复杂
引申:现在的Hotspot是使用直接指针的方式访问对象的
====================================================================
众所周知,JVM的内存是自动回收的,开发人员大多数情况下不需要手动申请(malloc)、释放(free)内存。但是像C、C++这类语言是需要手动申请、释放内存的。
手动管理内存的申请释放容易产生两种问题:
- 忘记释放
会导致内存泄露
- 反复释放
会导致释放有用的内存对象,比如下面这样:
#mermaid-svg-HvU66H3oNStb5nnM .label{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);fill:#333;color:#333}#mermaid-svg-HvU66H3oNStb5nnM .label text{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .node rect,#mermaid-svg-HvU66H3oNStb5nnM .node circle,#mermaid-svg-HvU66H3oNStb5nnM .node ellipse,#mermaid-svg-HvU66H3oNStb5nnM .node polygon,#mermaid-svg-HvU66H3oNStb5nnM .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-HvU66H3oNStb5nnM .node .label{text-align:center;fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .node.clickable{cursor:pointer}#mermaid-svg-HvU66H3oNStb5nnM .arrowheadPath{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-HvU66H3oNStb5nnM .flowchart-link{stroke:#333;fill:none}#mermaid-svg-HvU66H3oNStb5nnM .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-HvU66H3oNStb5nnM .edgeLabel rect{opacity:0.9}#mermaid-svg-HvU66H3oNStb5nnM .edgeLabel span{color:#333}#mermaid-svg-HvU66H3oNStb5nnM .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-HvU66H3oNStb5nnM .cluster text{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-HvU66H3oNStb5nnM .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-HvU66H3oNStb5nnM text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-HvU66H3oNStb5nnM .actor-line{stroke:grey}#mermaid-svg-HvU66H3oNStb5nnM .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-HvU66H3oNStb5nnM .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-HvU66H3oNStb5nnM #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-HvU66H3oNStb5nnM .sequenceNumber{fill:#fff}#mermaid-svg-HvU66H3oNStb5nnM #sequencenumber{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM #crosshead path{fill:#333;stroke:#333}#mermaid-svg-HvU66H3oNStb5nnM .messageText{fill:#333;stroke:#333}#mermaid-svg-HvU66H3oNStb5nnM .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-HvU66H3oNStb5nnM .labelText,#mermaid-svg-HvU66H3oNStb5nnM .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-HvU66H3oNStb5nnM .loopText,#mermaid-svg-HvU66H3oNStb5nnM .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-HvU66H3oNStb5nnM .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-HvU66H3oNStb5nnM .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-HvU66H3oNStb5nnM .noteText,#mermaid-svg-HvU66H3oNStb5nnM .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-HvU66H3oNStb5nnM .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-HvU66H3oNStb5nnM .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-HvU66H3oNStb5nnM .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-HvU66H3oNStb5nnM .mermaid-main-font{font-family:“trebuchet ms”, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .section{stroke:none;opacity:0.2}#mermaid-svg-HvU66H3oNStb5nnM .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-HvU66H3oNStb5nnM .section2{fill:#fff400}#mermaid-svg-HvU66H3oNStb5nnM .section1,#mermaid-svg-HvU66H3oNStb5nnM .section3{fill:#fff;opacity:0.2}#mermaid-svg-HvU66H3oNStb5nnM .sectionTitle0{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .sectionTitle1{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .sectionTitle2{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .sectionTitle3{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-HvU66H3oNStb5nnM .grid .tick text{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .grid path{stroke-width:0}#mermaid-svg-HvU66H3oNStb5nnM .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-HvU66H3oNStb5nnM .task{stroke-width:2}#mermaid-svg-HvU66H3oNStb5nnM .taskText{text-anchor:middle;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .taskText:not([font-size]){font-size:11px}#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-HvU66H3oNStb5nnM .task.clickable{cursor:pointer}#mermaid-svg-HvU66H3oNStb5nnM .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-HvU66H3oNStb5nnM .taskText0,#mermaid-svg-HvU66H3oNStb5nnM .taskText1,#mermaid-svg-HvU66H3oNStb5nnM .taskText2,#mermaid-svg-HvU66H3oNStb5nnM .taskText3{fill:#fff}#mermaid-svg-HvU66H3oNStb5nnM .task0,#mermaid-svg-HvU66H3oNStb5nnM .task1,#mermaid-svg-HvU66H3oNStb5nnM .task2,#mermaid-svg-HvU66H3oNStb5nnM .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutside0,#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutside2{fill:#000}#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutside1,#mermaid-svg-HvU66H3oNStb5nnM .taskTextOutside3{fill:#000}#mermaid-svg-HvU66H3oNStb5nnM .active0,#mermaid-svg-HvU66H3oNStb5nnM .active1,#mermaid-svg-HvU66H3oNStb5nnM .active2,#mermaid-svg-HvU66H3oNStb5nnM .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-HvU66H3oNStb5nnM .activeText0,#mermaid-svg-HvU66H3oNStb5nnM .activeText1,#mermaid-svg-HvU66H3oNStb5nnM .activeText2,#mermaid-svg-HvU66H3oNStb5nnM .activeText3{fill:#000 !important}#mermaid-svg-HvU66H3oNStb5nnM .done0,#mermaid-svg-HvU66H3oNStb5nnM .done1,#mermaid-svg-HvU66H3oNStb5nnM .done2,#mermaid-svg-HvU66H3oNStb5nnM .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-HvU66H3oNStb5nnM .doneText0,#mermaid-svg-HvU66H3oNStb5nnM .doneText1,#mermaid-svg-HvU66H3oNStb5nnM .doneText2,#mermaid-svg-HvU66H3oNStb5nnM .doneText3{fill:#000 !important}#mermaid-svg-HvU66H3oNStb5nnM .crit0,#mermaid-svg-HvU66H3oNStb5nnM .crit1,#mermaid-svg-HvU66H3oNStb5nnM .crit2,#mermaid-svg-HvU66H3oNStb5nnM .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-HvU66H3oNStb5nnM .activeCrit0,#mermaid-svg-HvU66H3oNStb5nnM .activeCrit1,#mermaid-svg-HvU66H3oNStb5nnM .activeCrit2,#mermaid-svg-HvU66H3oNStb5nnM .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-HvU66H3oNStb5nnM .doneCrit0,#mermaid-svg-HvU66H3oNStb5nnM .doneCrit1,#mermaid-svg-HvU66H3oNStb5nnM .doneCrit2,#mermaid-svg-HvU66H3oNStb5nnM .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-HvU66H3oNStb5nnM .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-HvU66H3oNStb5nnM .milestoneText{font-style:italic}#mermaid-svg-HvU66H3oNStb5nnM .doneCritText0,#mermaid-svg-HvU66H3oNStb5nnM .doneCritText1,#mermaid-svg-HvU66H3oNStb5nnM .doneCritText2,#mermaid-svg-HvU66H3oNStb5nnM .doneCritText3{fill:#000 !important}#mermaid-svg-HvU66H3oNStb5nnM .activeCritText0,#mermaid-svg-HvU66H3oNStb5nnM .activeCritText1,#mermaid-svg-HvU66H3oNStb5nnM .activeCritText2,#mermaid-svg-HvU66H3oNStb5nnM .activeCritText3{fill:#000 !important}#mermaid-svg-HvU66H3oNStb5nnM .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM g.classGroup text{fill:#9370db;stroke:none;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:10px}#mermaid-svg-HvU66H3oNStb5nnM g.classGroup text .title{font-weight:bolder}#mermaid-svg-HvU66H3oNStb5nnM g.clickable{cursor:pointer}#mermaid-svg-HvU66H3oNStb5nnM g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-HvU66H3oNStb5nnM g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-HvU66H3oNStb5nnM .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-HvU66H3oNStb5nnM .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-HvU66H3oNStb5nnM .dashed-line{stroke-dasharray:3}#mermaid-svg-HvU66H3oNStb5nnM #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM .commit-id,#mermaid-svg-HvU66H3oNStb5nnM .commit-msg,#mermaid-svg-HvU66H3oNStb5nnM .branch-label{fill:lightgrey;color:lightgrey;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .slice{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-HvU66H3oNStb5nnM g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-HvU66H3oNStb5nnM g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-HvU66H3oNStb5nnM g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-HvU66H3oNStb5nnM .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-HvU66H3oNStb5nnM .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-HvU66H3oNStb5nnM .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-HvU66H3oNStb5nnM .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-HvU66H3oNStb5nnM .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-HvU66H3oNStb5nnM .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-HvU66H3oNStb5nnM .edgeLabel text{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-HvU66H3oNStb5nnM .node circle.state-start{fill:black;stroke:black}#mermaid-svg-HvU66H3oNStb5nnM .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-HvU66H3oNStb5nnM #statediagram-barbEnd{fill:#9370db}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-state .divider{stroke:#9370db}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-HvU66H3oNStb5nnM .note-edge{stroke-dasharray:5}#mermaid-svg-HvU66H3oNStb5nnM .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{–mermaid-font-family: ‘“trebuchet ms”, verdana, arial’;–mermaid-font-family: “Comic Sans MS”, “Comic Sans”, cursive}#mermaid-svg-HvU66H3oNStb5nnM .error-icon{fill:#522}#mermaid-svg-HvU66H3oNStb5nnM .error-text{fill:#522;stroke:#522}#mermaid-svg-HvU66H3oNStb5nnM .edge-thickness-normal{stroke-width:2px}#mermaid-svg-HvU66H3oNStb5nnM .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-HvU66H3oNStb5nnM .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-HvU66H3oNStb5nnM .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-HvU66H3oNStb5nnM .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-HvU66H3oNStb5nnM .marker{fill:#333}#mermaid-svg-HvU66H3oNStb5nnM .marker.cross{stroke:#333} :root { --mermaid-font-family: “trebuchet ms”, verdana, arial;} #mermaid-svg-HvU66H3oNStb5nnM { color: rgba(0, 0, 0, 0.75); font: ; }
线程1
malloc
do something
free
do something
free
线程2
do something
do something
malloc
do something
线程1 M F F
线程2 M
也就是说线程1free了内存之后,线程2malloc了相同地址的内存,然后线程1反复释放了同一个地址的内存,这就会导致线程2在相同地址上创建的对象丢失
引用计数法
在引用计数法中,如果没有任何引用指向一个或多个对象,那么这些对象就是垃圾的
对象上记录了自己被引用的次数,每次引用会使引用次数+1,每次置空会使引用-1
存在的问题:引用计数法无法解决循环引用的问题
#mermaid-svg-1DF3262LK0r1j6mr .label{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);fill:#333;color:#333}#mermaid-svg-1DF3262LK0r1j6mr .label text{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .node rect,#mermaid-svg-1DF3262LK0r1j6mr .node circle,#mermaid-svg-1DF3262LK0r1j6mr .node ellipse,#mermaid-svg-1DF3262LK0r1j6mr .node polygon,#mermaid-svg-1DF3262LK0r1j6mr .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-1DF3262LK0r1j6mr .node .label{text-align:center;fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .node.clickable{cursor:pointer}#mermaid-svg-1DF3262LK0r1j6mr .arrowheadPath{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-1DF3262LK0r1j6mr .flowchart-link{stroke:#333;fill:none}#mermaid-svg-1DF3262LK0r1j6mr .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-1DF3262LK0r1j6mr .edgeLabel rect{opacity:0.9}#mermaid-svg-1DF3262LK0r1j6mr .edgeLabel span{color:#333}#mermaid-svg-1DF3262LK0r1j6mr .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-1DF3262LK0r1j6mr .cluster text{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-1DF3262LK0r1j6mr .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-1DF3262LK0r1j6mr text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-1DF3262LK0r1j6mr .actor-line{stroke:grey}#mermaid-svg-1DF3262LK0r1j6mr .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-1DF3262LK0r1j6mr .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-1DF3262LK0r1j6mr #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-1DF3262LK0r1j6mr .sequenceNumber{fill:#fff}#mermaid-svg-1DF3262LK0r1j6mr #sequencenumber{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr #crosshead path{fill:#333;stroke:#333}#mermaid-svg-1DF3262LK0r1j6mr .messageText{fill:#333;stroke:#333}#mermaid-svg-1DF3262LK0r1j6mr .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-1DF3262LK0r1j6mr .labelText,#mermaid-svg-1DF3262LK0r1j6mr .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-1DF3262LK0r1j6mr .loopText,#mermaid-svg-1DF3262LK0r1j6mr .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-1DF3262LK0r1j6mr .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-1DF3262LK0r1j6mr .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-1DF3262LK0r1j6mr .noteText,#mermaid-svg-1DF3262LK0r1j6mr .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-1DF3262LK0r1j6mr .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-1DF3262LK0r1j6mr .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-1DF3262LK0r1j6mr .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-1DF3262LK0r1j6mr .mermaid-main-font{font-family:“trebuchet ms”, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .section{stroke:none;opacity:0.2}#mermaid-svg-1DF3262LK0r1j6mr .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-1DF3262LK0r1j6mr .section2{fill:#fff400}#mermaid-svg-1DF3262LK0r1j6mr .section1,#mermaid-svg-1DF3262LK0r1j6mr .section3{fill:#fff;opacity:0.2}#mermaid-svg-1DF3262LK0r1j6mr .sectionTitle0{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .sectionTitle1{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .sectionTitle2{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .sectionTitle3{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-1DF3262LK0r1j6mr .grid .tick text{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .grid path{stroke-width:0}#mermaid-svg-1DF3262LK0r1j6mr .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-1DF3262LK0r1j6mr .task{stroke-width:2}#mermaid-svg-1DF3262LK0r1j6mr .taskText{text-anchor:middle;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .taskText:not([font-size]){font-size:11px}#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-1DF3262LK0r1j6mr .task.clickable{cursor:pointer}#mermaid-svg-1DF3262LK0r1j6mr .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-1DF3262LK0r1j6mr .taskText0,#mermaid-svg-1DF3262LK0r1j6mr .taskText1,#mermaid-svg-1DF3262LK0r1j6mr .taskText2,#mermaid-svg-1DF3262LK0r1j6mr .taskText3{fill:#fff}#mermaid-svg-1DF3262LK0r1j6mr .task0,#mermaid-svg-1DF3262LK0r1j6mr .task1,#mermaid-svg-1DF3262LK0r1j6mr .task2,#mermaid-svg-1DF3262LK0r1j6mr .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutside0,#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutside2{fill:#000}#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutside1,#mermaid-svg-1DF3262LK0r1j6mr .taskTextOutside3{fill:#000}#mermaid-svg-1DF3262LK0r1j6mr .active0,#mermaid-svg-1DF3262LK0r1j6mr .active1,#mermaid-svg-1DF3262LK0r1j6mr .active2,#mermaid-svg-1DF3262LK0r1j6mr .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-1DF3262LK0r1j6mr .activeText0,#mermaid-svg-1DF3262LK0r1j6mr .activeText1,#mermaid-svg-1DF3262LK0r1j6mr .activeText2,#mermaid-svg-1DF3262LK0r1j6mr .activeText3{fill:#000 !important}#mermaid-svg-1DF3262LK0r1j6mr .done0,#mermaid-svg-1DF3262LK0r1j6mr .done1,#mermaid-svg-1DF3262LK0r1j6mr .done2,#mermaid-svg-1DF3262LK0r1j6mr .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-1DF3262LK0r1j6mr .doneText0,#mermaid-svg-1DF3262LK0r1j6mr .doneText1,#mermaid-svg-1DF3262LK0r1j6mr .doneText2,#mermaid-svg-1DF3262LK0r1j6mr .doneText3{fill:#000 !important}#mermaid-svg-1DF3262LK0r1j6mr .crit0,#mermaid-svg-1DF3262LK0r1j6mr .crit1,#mermaid-svg-1DF3262LK0r1j6mr .crit2,#mermaid-svg-1DF3262LK0r1j6mr .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-1DF3262LK0r1j6mr .activeCrit0,#mermaid-svg-1DF3262LK0r1j6mr .activeCrit1,#mermaid-svg-1DF3262LK0r1j6mr .activeCrit2,#mermaid-svg-1DF3262LK0r1j6mr .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-1DF3262LK0r1j6mr .doneCrit0,#mermaid-svg-1DF3262LK0r1j6mr .doneCrit1,#mermaid-svg-1DF3262LK0r1j6mr .doneCrit2,#mermaid-svg-1DF3262LK0r1j6mr .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-1DF3262LK0r1j6mr .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-1DF3262LK0r1j6mr .milestoneText{font-style:italic}#mermaid-svg-1DF3262LK0r1j6mr .doneCritText0,#mermaid-svg-1DF3262LK0r1j6mr .doneCritText1,#mermaid-svg-1DF3262LK0r1j6mr .doneCritText2,#mermaid-svg-1DF3262LK0r1j6mr .doneCritText3{fill:#000 !important}#mermaid-svg-1DF3262LK0r1j6mr .activeCritText0,#mermaid-svg-1DF3262LK0r1j6mr .activeCritText1,#mermaid-svg-1DF3262LK0r1j6mr .activeCritText2,#mermaid-svg-1DF3262LK0r1j6mr .activeCritText3{fill:#000 !important}#mermaid-svg-1DF3262LK0r1j6mr .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr g.classGroup text{fill:#9370db;stroke:none;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family);font-size:10px}#mermaid-svg-1DF3262LK0r1j6mr g.classGroup text .title{font-weight:bolder}#mermaid-svg-1DF3262LK0r1j6mr g.clickable{cursor:pointer}#mermaid-svg-1DF3262LK0r1j6mr g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-1DF3262LK0r1j6mr g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-1DF3262LK0r1j6mr .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-1DF3262LK0r1j6mr .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-1DF3262LK0r1j6mr .dashed-line{stroke-dasharray:3}#mermaid-svg-1DF3262LK0r1j6mr #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr .commit-id,#mermaid-svg-1DF3262LK0r1j6mr .commit-msg,#mermaid-svg-1DF3262LK0r1j6mr .branch-label{fill:lightgrey;color:lightgrey;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .slice{font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-1DF3262LK0r1j6mr g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-1DF3262LK0r1j6mr g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-1DF3262LK0r1j6mr g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-1DF3262LK0r1j6mr .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-1DF3262LK0r1j6mr .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-1DF3262LK0r1j6mr .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-1DF3262LK0r1j6mr .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-1DF3262LK0r1j6mr .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-1DF3262LK0r1j6mr .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-1DF3262LK0r1j6mr .edgeLabel text{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:‘trebuchet ms’, verdana, arial;font-family:var(–mermaid-font-family)}#mermaid-svg-1DF3262LK0r1j6mr .node circle.state-start{fill:black;stroke:black}#mermaid-svg-1DF3262LK0r1j6mr .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-1DF3262LK0r1j6mr #statediagram-barbEnd{fill:#9370db}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-state .divider{stroke:#9370db}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-1DF3262LK0r1j6mr .note-edge{stroke-dasharray:5}#mermaid-svg-1DF3262LK0r1j6mr .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{–mermaid-font-family: ‘“trebuchet ms”, verdana, arial’;–mermaid-font-family: “Comic Sans MS”, “Comic Sans”, cursive}#mermaid-svg-1DF3262LK0r1j6mr .error-icon{fill:#522}#mermaid-svg-1DF3262LK0r1j6mr .error-text{fill:#522;stroke:#522}#mermaid-svg-1DF3262LK0r1j6mr .edge-thickness-normal{stroke-width:2px}#mermaid-svg-1DF3262LK0r1j6mr .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-1DF3262LK0r1j6mr .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-1DF3262LK0r1j6mr .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-1DF3262LK0r1j6mr .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-1DF3262LK0r1j6mr .marker{fill:#333}#mermaid-svg-1DF3262LK0r1j6mr .marker.cross{stroke:#333} :root { --mermaid-font-family: “trebuchet ms”, verdana, arial;} #mermaid-svg-1DF3262LK0r1j6mr { color: rgba(0, 0, 0, 0.75); font: ; }
引用
引用
对象1
对象2
上面这种引用关系下,对象1
的引用计数为1,对象2
的引用计数也是1,虽然它们与整体已经没有任何关系,但是因为彼此之间持有引用,就导致引用计数!=0
最终无法被回收
总目录展示
该笔记共八个节点(由浅入深),分为三大模块。
高性能。 秒杀涉及大量的并发读和并发写,因此支持高并发访问这点非常关键。该笔记将从设计数据的动静分离方案、热点的发现与隔离、请求的削峰与分层过滤、服务端的极致优化这4个方面重点介绍。
一致性。 秒杀中商品减库存的实现方式同样关键。可想而知,有限数量的商品在同一时刻被很多倍的请求同时来减库存,减库存又分为“拍下减库存”“付款减库存”以及预扣等几种,在大并发更新的过程中都要保证数据的准确性,其难度可想而知。因此,将用一个节点来专门讲解如何设计秒杀减库存方案。
高可用。 虽然介绍了很多极致的优化思路,但现实中总难免出现一些我们考虑不到的情况,所以要保证系统的高可用和正确性,还要设计一个PlanB来兜底,以便在最坏情况发生时仍然能够从容应对。笔记的最后,将带你思考可以从哪些环节来设计兜底方案。
篇幅有限,无法一个模块一个模块详细的展示(这些要点都收集在了这份《高并发秒杀顶级教程》里),麻烦各位转发一下(可以帮助更多的人看到哟!)
由于内容太多,这里只截取部分的内容。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
发秒杀顶级教程》里),麻烦各位转发一下(可以帮助更多的人看到哟!)
[外链图片转存中…(img-pwjyAwRV-1713422185848)]
[外链图片转存中…(img-YaVHKjF4-1713422185848)]
由于内容太多,这里只截取部分的内容。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-MMFO0lKU-1713422185849)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!