SlideShare a Scribd company logo
垃圾收集四讲
UVGE 刘清
• 历史与发展
• 优缺点
• 原理
• 实现
历史与发展
• LISP
• ML 系语言
• JVM
• C++
• Perl/Python/Ruby
• CLR
优缺点
优点:
a)方便
b)可靠
缺点:
• 时间及空间的开销
• 实现和移植的复杂性
( JVM 和 KVM )
• 底层操作的实现
• 对对象模型的影响
优缺点
改善:
• 可选式 GC
• 允许显式引入不安全操作
原理
• 引用计数
– 缺点:循环引用
循环引用
A
B
1
1
标记 - 清扫算法
• 寻找根对象并标记
• 按照广度优先遍历算
法进行遍历标记
• 任何被标记的都是存
活对象,不会被清除
• 进行清扫过程
√
√
√
√
原理
• 引用计数
– 缺点:循环引用
• 标记 - 清扫
– 缺点:效率
原理
• 引用计数
– 缺点:循环引用
• 标记 - 清扫
– 缺点:效率
• 分代式收集( 2 : 8 原则)
– 80% 的对象只存活于 %20 的程序生命期
分代式垃圾收集
Gen0
Gen1
Gen2
Gen0
分代式垃圾收集
Gen0
Gen1
Gen2
Gen0
分代式垃圾收集
Gen1
Gen2
Gen0
分代式垃圾收集
Gen1
Gen2
Gen0
分代式垃圾收集
Gen1
Gen2
Gen0
分代式垃圾收集
Gen2
Gen0
Gen1
分代式垃圾收集
Gen2
Gen0
Gen1
分代式垃圾收集
Gen2
Gen0
Gen1
分代式垃圾收集
Gen0
Gen2
Gen1
分代式垃圾收集
Gen0
Gen1
Gen2
Gen0
Gen2
Gen1
原理
• 引用计数
– 缺点:循环引用
• 标记 - 清扫
– 缺点:效率
• 分代式收集( 2 : 8 原则)
– 80% 的对象只存活于 %20 的程序生命期
• 复制 - 缩并
– 小内存:只使用缩并算法
实现

More Related Content

Viewers also liked

Vert.X mini-talk
Vert.X mini-talkVert.X mini-talk
Vert.X mini-talk
Norman Richards
 
Breaking the Fourth Wall in Software
Breaking the Fourth Wall in SoftwareBreaking the Fourth Wall in Software
Breaking the Fourth Wall in Software
Alex Bunardzic
 
From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)
Alex Bunardzic
 
JBatch
JBatchJBatch
Harnessing asynchronicity callbacks, promises, generators, and coroutines
Harnessing asynchronicity   callbacks, promises, generators, and coroutinesHarnessing asynchronicity   callbacks, promises, generators, and coroutines
Harnessing asynchronicity callbacks, promises, generators, and coroutines
Haokang Den
 
In-Memory Computing - Distributed Systems - Devoxx UK 2015
In-Memory Computing - Distributed Systems - Devoxx UK 2015In-Memory Computing - Distributed Systems - Devoxx UK 2015
In-Memory Computing - Distributed Systems - Devoxx UK 2015
Christoph Engelbert
 
Vert.x 3
Vert.x 3Vert.x 3
Vert.x 3
Xavier MARIN
 
Principles of the Play framework
Principles of the Play frameworkPrinciples of the Play framework
Principles of the Play framework
Bernhard Huemer
 
An Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptAn Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScript
Norman Richards
 
Taming complexity in JavaScript
Taming complexity in JavaScriptTaming complexity in JavaScript
Taming complexity in JavaScript
Binary Studio
 
Recursion schemes in Scala
Recursion schemes in ScalaRecursion schemes in Scala
Recursion schemes in Scala
Arthur Kushka
 
Event driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetesEvent driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetes
Andy Moncsek
 
Functional programming
Functional programmingFunctional programming
Functional programming
edusmildo
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
Bernhard Huemer
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
Александр Федоров
 
autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3
Andy Moncsek
 
Lambda Calculus
Lambda CalculusLambda Calculus
Lambda Calculus
K. N. Toosi University
 
Introduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculusIntroduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculus
Kim Leo
 
Pointers and References
Pointers and ReferencesPointers and References
Pointers and References
Kim Leo
 

Viewers also liked (19)

Vert.X mini-talk
Vert.X mini-talkVert.X mini-talk
Vert.X mini-talk
 
Breaking the Fourth Wall in Software
Breaking the Fourth Wall in SoftwareBreaking the Fourth Wall in Software
Breaking the Fourth Wall in Software
 
From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)
 
JBatch
JBatchJBatch
JBatch
 
Harnessing asynchronicity callbacks, promises, generators, and coroutines
Harnessing asynchronicity   callbacks, promises, generators, and coroutinesHarnessing asynchronicity   callbacks, promises, generators, and coroutines
Harnessing asynchronicity callbacks, promises, generators, and coroutines
 
In-Memory Computing - Distributed Systems - Devoxx UK 2015
In-Memory Computing - Distributed Systems - Devoxx UK 2015In-Memory Computing - Distributed Systems - Devoxx UK 2015
In-Memory Computing - Distributed Systems - Devoxx UK 2015
 
Vert.x 3
Vert.x 3Vert.x 3
Vert.x 3
 
Principles of the Play framework
Principles of the Play frameworkPrinciples of the Play framework
Principles of the Play framework
 
An Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptAn Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScript
 
Taming complexity in JavaScript
Taming complexity in JavaScriptTaming complexity in JavaScript
Taming complexity in JavaScript
 
Recursion schemes in Scala
Recursion schemes in ScalaRecursion schemes in Scala
Recursion schemes in Scala
 
Event driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetesEvent driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetes
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
 
autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3
 
Lambda Calculus
Lambda CalculusLambda Calculus
Lambda Calculus
 
Introduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculusIntroduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculus
 
Pointers and References
Pointers and ReferencesPointers and References
Pointers and References
 

Similar to Garbage collection

快速搭建高性能服务端
快速搭建高性能服务端快速搭建高性能服务端
快速搭建高性能服务端moonbingbing
 
QCon - 一次 Clojure Web 编程实战
QCon - 一次 Clojure Web 编程实战QCon - 一次 Clojure Web 编程实战
QCon - 一次 Clojure Web 编程实战
dennis zhuang
 
网站前端代码静态检查工具研究
网站前端代码静态检查工具研究网站前端代码静态检查工具研究
网站前端代码静态检查工具研究
pop2008
 
网站前端代码静态检查工具综述
网站前端代码静态检查工具综述网站前端代码静态检查工具综述
网站前端代码静态检查工具综述pop2008
 
淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践丁 宇
 
淘宝前台系统性能分析与优化
淘宝前台系统性能分析与优化淘宝前台系统性能分析与优化
淘宝前台系统性能分析与优化丁 宇
 
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
Paul Chao
 
廣宣學堂: 企業導入微服務實戰
廣宣學堂: 企業導入微服務實戰廣宣學堂: 企業導入微服務實戰
廣宣學堂: 企業導入微服務實戰
Paul Chao
 
網路技術心得分享
網路技術心得分享網路技術心得分享
網路技術心得分享
Mux Baxer
 
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
Paul Chao
 
Debug Your Kubernetes Network
Debug Your Kubernetes NetworkDebug Your Kubernetes Network
Debug Your Kubernetes Network
HungWei Chiu
 
调试技术的应用
调试技术的应用调试技术的应用
调试技术的应用延胜 黄
 
推荐系统:从入门到放弃
推荐系统:从入门到放弃推荐系统:从入门到放弃
推荐系统:从入门到放弃
xiaogaozi
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
Angel Boy
 
Nodejs & NAE
Nodejs & NAENodejs & NAE
Nodejs & NAEq3boy
 
大型互联网站性能优化
大型互联网站性能优化大型互联网站性能优化
大型互联网站性能优化丁 宇
 
Comment System of 56.com
Comment System of 56.comComment System of 56.com
Comment System of 56.com
Ho Kim
 
了解应用服务器
了解应用服务器了解应用服务器
了解应用服务器
Feng Yu
 
Overview - QML and C++ Integration
Overview - QML and C++ IntegrationOverview - QML and C++ Integration
Overview - QML and C++ Integration
Yun-Lin Huang
 
mercury
mercurymercury
mercury
moonbingbing
 

Similar to Garbage collection (20)

快速搭建高性能服务端
快速搭建高性能服务端快速搭建高性能服务端
快速搭建高性能服务端
 
QCon - 一次 Clojure Web 编程实战
QCon - 一次 Clojure Web 编程实战QCon - 一次 Clojure Web 编程实战
QCon - 一次 Clojure Web 编程实战
 
网站前端代码静态检查工具研究
网站前端代码静态检查工具研究网站前端代码静态检查工具研究
网站前端代码静态检查工具研究
 
网站前端代码静态检查工具综述
网站前端代码静态检查工具综述网站前端代码静态检查工具综述
网站前端代码静态检查工具综述
 
淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践淘宝网前台应用性能优化实践
淘宝网前台应用性能优化实践
 
淘宝前台系统性能分析与优化
淘宝前台系统性能分析与优化淘宝前台系统性能分析与优化
淘宝前台系统性能分析与优化
 
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
 
廣宣學堂: 企業導入微服務實戰
廣宣學堂: 企業導入微服務實戰廣宣學堂: 企業導入微服務實戰
廣宣學堂: 企業導入微服務實戰
 
網路技術心得分享
網路技術心得分享網路技術心得分享
網路技術心得分享
 
企業導入微服務實戰 - updated
企業導入微服務實戰 - updated企業導入微服務實戰 - updated
企業導入微服務實戰 - updated
 
Debug Your Kubernetes Network
Debug Your Kubernetes NetworkDebug Your Kubernetes Network
Debug Your Kubernetes Network
 
调试技术的应用
调试技术的应用调试技术的应用
调试技术的应用
 
推荐系统:从入门到放弃
推荐系统:从入门到放弃推荐系统:从入门到放弃
推荐系统:从入门到放弃
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
Nodejs & NAE
Nodejs & NAENodejs & NAE
Nodejs & NAE
 
大型互联网站性能优化
大型互联网站性能优化大型互联网站性能优化
大型互联网站性能优化
 
Comment System of 56.com
Comment System of 56.comComment System of 56.com
Comment System of 56.com
 
了解应用服务器
了解应用服务器了解应用服务器
了解应用服务器
 
Overview - QML and C++ Integration
Overview - QML and C++ IntegrationOverview - QML and C++ Integration
Overview - QML and C++ Integration
 
mercury
mercurymercury
mercury
 

Garbage collection