STW

Tracing garbage collection - Wikipedia https://en.wikipedia.org/wiki/Tracing_garbage_collection#Stop-the-world_vs._incremental_vs._concurrent

Stop-the-world vs. incremental vs. concurrent[edit]

Simple stop-the-world garbage collectors completely halt execution of the program to run a collection cycle, thus guaranteeing that new objects are not allocated and objects do not suddenly become unreachable while the collector is running.

This has the disadvantage that the program can perform no useful work while a collection cycle is running (sometimes called the "embarrassing pause"[6]). Stop-the-world garbage collection is therefore mainly suitable for non-interactive programs. Its advantage is that it is both simpler to implement and faster than incremental garbage collection.

Incremental and concurrent garbage collectors are designed to reduce this disruption by interleaving their work with activity from the main program. Incremental garbage collectors perform the garbage collection cycle in discrete phases, with program execution permitted between each phase (and sometimes during some phases). Concurrent garbage collectors do not stop program execution at all, except perhaps briefly when the program's execution stack is scanned. However, the sum of the incremental phases takes longer to complete than one batch garbage collection pass, so these garbage collectors may yield lower total throughput.

Careful design is necessary with these techniques to ensure that the main program does not interfere with the garbage collector and vice versa; for example, when the program needs to allocate a new object, the runtime system may either need to suspend it until the collection cycle is complete, or somehow notify the garbage collector that there exists a new, reachable object.

https://zh.wikipedia.org/wiki/追踪垃圾回收

在计算机编程中,跟踪垃圾收集(英语: Tracing garbage collection )是一种自动内存管理的算法,该算法通过分析某些“根”对象的引用关系,来确定需要保留的可访问对象,并释放其余的不可访问对象的内存空间。该算法在实际的软件工程中得到了广泛的应用。[1][2]

跟踪垃圾收集是最常见的垃圾收集方式,以至于“垃圾收集”通常是指跟踪垃圾收集,而不是引用计数之类的其他方法[原创研究?]

对象的可达性[编辑]

简单地说,如果可以从任何一个已经定义的变量开始,直接或者通过其他对象的引用来访问到某个对象,则该对象是可访问的。[原创研究?]更准确地说,只有以下两种对象是可达的:

  • 程序代码直接定义的变量与对象都是可达的。通常这些对象包括从调用堆栈中任何位置引用的所有对象(即当前正在调用的函数中的所有局部变量和参数)以及任何全局变量[原创研究?]
  • 可访问对象引用的任何对象都是可达的。[2]也就是说,可达性是传递闭包的。

强引用和弱引用[编辑]

弱集合[编辑]

基本算法[编辑]

朴素的标记和扫描[编辑]

标记-移动算法[编辑]

参考连结[编辑]

  1. ^ Concurrent Mark Sweep (CMS) Collector. Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide. Oracle Java Documentation. [2020-03-12] (英语)The CMS collector ... is a tracing collector that identifies at least all the reachable objects in the heap.
  2. 跳转至:2.0 2.1 吴, 昊; 季, 振洲. 一种基于半空间的不完全拷贝垃圾回收机制. 哈尔滨工业大学学报. 2011, 43 (11): 60–64 [2020-03-27]ISSN 0367-6234.

 

 

 

 

 

在计算机编程中,跟踪垃圾收集(英语: Tracing garbage collection )是一种自动内存管理的算法,该算法通过分析某些“根”对象的引用关系,来确定需要保留的可访问对象,并释放其余的不可访问对象的内存空间。该算法在实际的软件工程中得到了广泛的应用。[1][2]

跟踪垃圾收集是最常见的垃圾收集方式,以至于“垃圾收集”通常是指跟踪垃圾收集,而不是引用计数之类的其他方法[原创研究?]

对象的可达性[编辑]

简单地说,如果可以从任何一个已经定义的变量开始,直接或者通过其他对象的引用来访问到某个对象,则该对象是可访问的。[原创研究?]更准确地说,只有以下两种对象是可达的:

  • 程序代码直接定义的变量与对象都是可达的。通常这些对象包括从调用堆栈中任何位置引用的所有对象(即当前正在调用的函数中的所有局部变量和参数)以及任何全局变量[原创研究?]
  • 可访问对象引用的任何对象都是可达的。[2]也就是说,可达性是传递闭包的。

强引用和弱引用[编辑]

弱集合[编辑]

基本算法[编辑]

朴素的标记和扫描[编辑]

标记-移动算法[编辑]

参考连结[编辑]

  1. ^ Concurrent Mark Sweep (CMS) Collector. Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide. Oracle Java Documentation. [2020-03-12] (英语)The CMS collector ... is a tracing collector that identifies at least all the reachable objects in the heap.
  2. 跳转至:2.0 2.1 吴, 昊; 季, 振洲. 一种基于半空间的不完全拷贝垃圾回收机制. 哈尔滨工业大学学报. 2011, 43 (11): 60–64 [2020-03-27]ISSN 0367-6234.
posted @ 2019-03-09 17:19  papering  阅读(493)  评论(0编辑  收藏  举报