I use the following simple JavaScript code to illustrate:
var JerryTestArray = [];
(function(){
for( var i = 0; i < 100; i++){
JerryTestArray[i] = document.createElement("div");
}
})();
Create a new empty tab in your Chrome, and first create a snapshot with empty heap status by click “Take Snapshot” button:
The Snapshot1 is generated.
Now switch to tab Console, paste the JavaScript code and execute it in console.
And switch to Profiles tab again to make the second snapshot:
Once done, select the second snapshot, choose “Comparison” and “Snapshot1” as filter:
We can find out from column “New” that 100 div nodes are created as we expect.
Since these nodes are not appended to document node so they are invisible to end user, so displayed as “Detached DOM”. The JerryTestArray still holds the reference to each div node so Garbage collector will not touch these nodes.
In order to make Garbage collector recycle the memory occupied by these nodes, just assign another value to JerryTestArray in console:
Once done, make the third snapshot and compare it with the second. Now we can find that the re-assignment to JerryTestArray will trigger the destruction of those 100 div nodes by Garbage collector:
Meanwhile, the string we use in assignment could also be inspected via the combination of filters below:
There is another kind of profile in Chrome development tool which can give you an overview about timeline of memory allocation:
Click Start button in above screenshot, and paste the following code in console and executed:
var JerryTestArray = [];
(function(){
for( var i = 0; i < 98; i++){
JerryTestArray[i] = document.createElement("span");
JerryTestArray[i].className = "JerryClassName" + i;
}
})();
After the code is executed, paste the following code and execute:
JerryTestArray[30] = "this is a long test............................end";
Now stop the profile. The profile is displayed as below. The highlighted vertical blue line indicates the timeslot when the 97 Span elements are created. Note that the number of Span elements displayed here is not 98 but 97 since Chrome development tool displays the final status of objects after “stop profile” button is clicked ( the reference to 30th Span element is replaced by String, so it is recycled by GC ).
You can drag the two vertical bars to define the time range between which you would like to inspect. For example the time range below contains the timeslot when the below assignment occurs:
JerryTestArray[30] = "this is a long test............................end";
With this gained knowledge now we can check the memory allocation and destruction in some real application. For example click tile “My Tasks” to enter this application, make the first snapshot and click back button within application to return to launchpad, and make the second snapshot and review the comparison result.
From the result we find out lots of stuff are deleted after we return to launchpad:
Hover your mouse to a given destructed object and you can review its detail:
For more tips How I use Chrome development tool in my daily work, please refer to this blog Chrome Development Tool tips used in my daily work
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
系统级编程的课程实验,实现内存的的自动回收管理。 这里需要声明的是,资源不是来自本人,资源来自网络。本着造福广大学生的目的。但是本人实在太菜,不知道如何设置资源分数为0,所以就设置为1. 另外,代码在vs...
IBM Pattern Modeling and Analysis Tool for Java Garbage Collector
[GA458]IBM Pattern Modeling and Analysis Tool for Java Garbage Collector
自动垃圾回收虽然会对性能造成一定的影响,但在大对对性能要求不是特别苛刻的场合下,使用自动垃圾回收技术可以极大的方便软件开发,降低由内存泄漏所引发的问题。 C++的自动垃圾回收库早就有了几个,商业和非商业的...
IBM Pattern Modelin and Analysis Tool for Java Garbage Collector IBM Weblogic Application Service(WAS)GC(垃圾回收)日志分析工具
Activation KMS Garbage Collector v1.3.4
The Garbage Collection Cookbook 垃圾回收算法手册
IBM的java 内存回收分析工具,用于分析gc日志
CMU的垃圾回收实验(IN C) 1.这个实验由我主讲,我制作了PPT,包含三种思路, 2.并提供其中最重要也是最简单的扫描Stack Frame的源码。 3.此外,有整体思考的思维导图,供全局预览。
很久之前就一直在学习JVM,但是一直也没有好好的总结,最近终于有了空闲,将之前学习的内容整理成了一个PPT。PPT也可以在这里下载: ... 也希望大神们可以批评指正。 ppt中主要包含下面几部分: ...垃圾收集器
在Java面试中,垃圾回收(Garbage Collection)是一个非常重要的话题。下面是一份面试分析,以及垃圾回收在面试中的占比和重要性。 面试分析: 知识点覆盖范围:垃圾回收算法、垃圾收集器、GC原理、垃圾回收的优...
使用了着色指针技术,使用读屏障来解决 GC 线程和应用线程可能并发修改对象状态的问题,基于 Region不分代,支持NUMA,低延迟10ms
The Garbage Collection Handbook 关于垃圾回收器算法的书籍,非常不错
lab_garbage_collector.zip
系统级编程实验,利用C语言实现垃圾回收器,避免在malloc分配内存后忘记free,导致内存泄漏等一些严重后果
著名的C/C++垃圾回收站
Java Garbage Collection Study java 垃圾回收学习
垃圾回收算法的经典著作之一,常见的垃圾回收算法 【中文版】 垃圾回收算法的经典著作之一,常见的垃圾回收算法 【中文版】
垃圾收集GC(Garbage Collection)是Java语言的核心技术之一,之前我们曾专门探讨过Java 7新增的垃圾回收器G1的新特性,但在JVM的内部运行机制上看,Java的垃圾回收原理与机制并未改变。垃圾收集的目的在于清除不再...