Fundamentals of Garbage Collection

1、Reclaims objects that are no longer being used, clears their memory, and keeps the memory available for future allocations. Managed objects automatically get clean content to start with, so their constructors do not have to initialize every data field.

2、Visual memory can be in three states:

  1)Free. The block of memory has no references to it and is available for allocation.

  2)Reserved. The block of memory is available for your use and cannot be used for any other allocation request. However, you cannot store data to this memory block until it is committed.

  3)Committed. The block of memory is assigned to physical storage.

3、Virtual address space can get fragmented. This means that there are free blocks, also known as holes, in the address space. When a virtual memory allocation is requested, the virtual memory manager has to find a single free block that is large enough to satisfy that allocation request. Even if you have 2 GB of free space, the allocation that requires 2 GB will be unsuccessful unless all of that space is in a single address block.

4、Conditions for a Garbage Collection.

  Garbage collection occurs when one of the following conditions is true:

  • The system has low physical memory.(被动)

  • The memory that is used by allocated objects on the managed heap surpasses an acceptable threshold. This means that a threshold of acceptable memory usage has been exceeded on the managed heap. This threshold is continuously adjusted as the process runs.(被动)

  • The GC. Collect method is called. (主动)

5、When a garbage collection is triggered, the garbage collector reclaims the memory that is occupied by dead objects. The reclaiming process compacts live objects so that they are moved together, and the dead space is removed, thereby making the heap smaller. This ensures that objects that are allocated together stay together on the managed heap, to preserve their locality.

6、The heap can be considered as the accumulation of two heaps: the large object heap and the small object heap.

   The large object heap contains objects that are 85,000 bytes and larger. Very large objects on the large object heap are usually arrays. It is rare for an instance object to be extremely large.

Generations

1、There are three generations of objects on the heap: 0、1、2。

2、Newly allocated objects form a new generation of objects and are implicitly generation 0 collections, unless they are large objects, in which case they go on the large object heap in a generation 2 collection.

3、每一次GC幸存下来的对象,会晋升到更高级的Generation。

4、Generation 0、1 也叫作 ephemeral generation。0、1必须在ephemeral segment中。ephemeral segment中可以有2.

5、The amount of freed memory from an ephemeral garbage collection is limited to the size of the ephemeral segment

What Happens During a Garbage Collection

  Before a garbage collection starts, all managed threads are suspended except for the thread that triggered the garbage collection

  

  When a finalizable object is discovered to be dead, its finalizer is put in a queue so that its cleanup actions are executed, but the object itself is promoted to the next generation. Therefore, you have to wait until the next garbage collection that occurs on that generation (which is not necessarily the next garbage collection) to determine whether the object has been reclaimed.

  GC分为2种:Workstation、Server。Server类有专门的GC线程。

  

  Workstation并发GC模型。此模型下,0、1同步完成,2在GC线程中完成。

    

  

  

  

Fundamentals of Garbage Collection的更多相关文章

  1. 从ASP.NET Core 3.0 preview 特性,了解CLR的Garbage Collection

    前言 在阅读这篇文章:Announcing Net Core 3 Preview3的时候,我看到了这样一个特性: Docker and cgroup memory Limits We conclude ...

  2. Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译

    本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

  3. How Garbage Collection Really Works

    Java Memory Management, with its built-in garbage collection, is one of the language's finest achiev ...

  4. Java Garbage Collection Basics--转载

    原文地址:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Overview Purpose ...

  5. AutoReleasePool 和 ARC 以及Garbage Collection

    AutoReleasePool autoreleasepool并不是总是被auto 创建,然后自动维护应用创建的对象. 自动创建的情况如下: 1. 使用NSThread的detachNewThread ...

  6. [翻译]Java垃圾收集精粹(Java Garbage Collection Distilled)

    source URL: http://www.infoq.com/articles/Java_Garbage_Collection_Distilled Name: Java Garbage Colle ...

  7. The Impact of Garbage Collection on Application Performance

    As we’ve seen, the performance of the garbage collector is not determined by the number of dead obje ...

  8. [Java] 垃圾回收 ( Garbage Collection ) 的步骤演示

    关于 JVM 垃圾回收机制的基础内容,可参考上一篇博客 垃圾回收机制 ( Garbage Collection ) 简介 上一篇博客,介绍了堆的内存被分为三个部分:年轻代.老年代.永生代.这篇博文将演 ...

  9. [Java] 垃圾回收机制 ( Garbage Collection ) 简介

    自动垃圾回收( Automatic Garbage Collection ) 自动垃圾回收,是指在堆(Heap)内存上分辨哪些对象还在被使用,哪些对象没有被使用,并清除没有被使用的对象.所以,这里的垃 ...

随机推荐

  1. kmp&扩展kmp

    kmp: KMP的主要目的是求B是不是A的子串,以及若是,B在A中所有出现的位置 写的很详细的大佬的博客:http://www.matrix67.com/blog/archives/115 模板: / ...

  2. Big Table中文翻译

    题记:google 的成功除了一个个出色的创意外,还因为有 Jeff Dean 这样的软件架构天才. 官方的 Google Reader blog 中有对BigTable 的解释.这是Google 内 ...

  3. 网站微信登录-python 实现

    最近微信登录开放公测,为了方便微信用户使用,我们的产品也决定加上微信登录功能,然后就有了这篇笔记. 根据需求选择相应的登录方式 微信现在提供两种登录接入方式 移动应用微信登录 网站应用微信登录 这里我 ...

  4. celery docker 基本使用

    项目参考官网资料,比较简单的add task 具体代码参考https://github.com/rongfengliang/celery-docker-demo 项目结构 ├── README.md ...

  5. bootstrap 在超小屏布局时使用 clearfix

    bootstrap 在超小屏布局时使用 clearfix 先看案例,一共四个 div,使用 col-xs-6, 所以在特别小型设备上时会变成两行. 不过我们发现如果第一个 div 内容多了后会变成如下 ...

  6. 指向NULL的类

    引出:写个类A,声明类A指针指向NULL,调用类A的方法会有什么后果,编译通过吗,运行会通过吗? (在VS2008与VC++的情况下) 有错误欢迎批评指正! #include<stdio.h&g ...

  7. 机器学习The Learning Problem——coursera简要总结

    1.人类及动物的学习模式:观察->学习->技能 机器学习的模式:data->ML(机器学习)->skill 2.那什么是skill:技能是某种表现方法的增进   eg:stac ...

  8. 为什么JSP会比Beetl慢

    转自:http://my.oschina.net/xiandafu/blog/475740 JSP是预编译成class的,然后模板渲染里比Beetl慢很多,文章从JSP静态文本处理不足,以及JSTL实 ...

  9. 黄聪:Windows 64位系统中安装Android SDK“系统找不到指定的文件Java.exe”解决方法

    明明已经在64位window7中安装好了64位版本的jdk,为什么android SDK安装程序却识别不到jdk呢?先看看报错: Java SE Development Kit (JDK) not f ...

  10. 积木城堡(dp)

    题目描述 XC的儿子小XC最喜欢玩的游戏用积木垒漂亮的城堡.城堡是用一些立方体的积木垒成的,城堡的每一层是一块积木.小XC是一个比他爸爸XC还聪明的孩子,他发现垒城堡的时候,如果下面的积木比上面的积木 ...