Managed Heaps

In general it can be categorized into 1) SOH and 2) LOH.  size lower than 85K will be in SOH, size larger than 85K will be in LOH.

Small Object Heap

GC will do 1) Mark 2) Sweep 3) Compact on SOH.

How GC works

When a small object is created (less than 85KB in size), it is stored in the small object heap. The CLR organizes the small object heap into three generations – generation 0, generation 1, and generation 2 – that are collected at different intervals. Small objects are generally allocated to generation 0, and if they survive a GC cycle, they are promoted to generation 1. If they survive the next GC cycle, they are promoted to generation 2.

Further, garbage collection of the small object heap includes compaction, meaning that as unused objects are collected, the GC moves living objects into the gaps to eliminate fragmentation and make sure that the available memory is contiguous. Of course, compaction involves overhead – both CPU cycles and additional memory for copying objects. Because the benefits of compaction outweigh the costs for small objects, compaction is performed automatically on the small object heap.

GC uses generational garbition collection. .Net will device memory into 3 generations. Gen 0 is the youngest one, Gen 2 is the olddest one.

Gen 0 collection will empty Gen 0 for sure. Either move the objects to Gen 1, or Die and compact the rootless objects.

Gen 1 collection will scan gen 0 and gen 1 both, for objects still has root reference, move them from gen 0 to gen 1, and move the ones in gen 1 to gen 2.

Gen 2 is a full collection because all of the generations are inspected and colleted.

Gen 0, Gen 1 and Gen 2 are 10 times difference compared to each other.

Some object may have un-managed resources, so these objects will have their reference added to the Finalization Queue.  There is a seperate thread other than GC which will run and call Finalize () method to recycle the objects.

For rootless objects, collect them. in SOH, compact the available space.  in LOH, it does not do compaction, but it will maintain a free memory table.  next time, when there is a object > 85KB, it will check free table firstly, if it can accomodate the object, save it, if not, do fragmentation and allocate new memory.

.Net memory management Learning Notes的更多相关文章

  1. Operating System Memory Management、Page Fault Exception、Cache Replacement Strategy Learning、LRU Algorithm

    目录 . 引言 . 页表 . 结构化内存管理 . 物理内存的管理 . SLAB分配器 . 处理器高速缓存和TLB控制 . 内存管理的概念 . 内存覆盖与内存交换 . 内存连续分配管理方式 . 内存非连 ...

  2. Obj-C Memory Management

    Memory management is one of the most important process in any programming language. It is the proces ...

  3. Memory Management in Open Cascade

    Open Cascade中的内存管理 Memory Management in Open Cascade eryar@163.com 一.C++中的内存管理 Memory Management in ...

  4. Java (JVM) Memory Model – Memory Management in Java

    原文地址:http://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java Understanding JV ...

  5. Objective-C Memory Management

    Objective-C Memory Management Using Reference Counting 每一个从NSObject派生的对象都继承了对应的内存管理的行为.这些类的内部存在一个称为r ...

  6. Android内存管理(2)HUNTING YOUR LEAKS: MEMORY MANAGEMENT IN ANDROID PART 2

    from: http://www.raizlabs.com/dev/2014/04/hunting-your-leaks-memory-management-in-android-part-2-of- ...

  7. Android内存管理(1)WRANGLING DALVIK: MEMORY MANAGEMENT IN ANDROID PART 1

    from : http://www.raizlabs.com/dev/2014/03/wrangling-dalvik-memory-management-in-android-part-1-of-2 ...

  8. Understanding Memory Management(2)

    Understanding Memory Management Memory management is the process of allocating new objects and remov ...

  9. Java Memory Management(1)

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

随机推荐

  1. PHP的openssl_encrypt方法的Java实现

    <?php class OpenSSL3DES { /*密钥,22个字符*/ const KEY='09bd821d3e764f44899a9dc6'; /*向量,8个或10个字符*/ cons ...

  2. react - next.js 引用本地图片和css文件

    1. 图片 把图片放在/static/文件夹中,在component中用img tag: <img src={'../static/icon.png'} /> 2. css 把css文件放 ...

  3. win7系统内网共享打印机设置

    工作中通常使用内网,你同事的计算机连接了一台打印机,老板没给你单独配打印机,莫慌,你可以通过内网连接同事的打印机. 1.在你同事的电脑上启用来宾账户并按照链接设置:https://jingyan.ba ...

  4. Intellij IDEA 自动清除无效 import

    打开偏好设置: 输入auto import: 注:想在以后的工程中都自动清除,可以在File中如下图操作:

  5. JRebel springboot部署idea

    JRebel springboot部署idea     http://127.0.0.1:8888/88414687-3b91-4286-89ba-2dc813b107ce   ctrl+shift+ ...

  6. linux php5.6 安装Redis扩展

    wget http://pecl.php.net/get/redis-4.2.0.tgz tar -zxvf redis-.tgz cd redis- /usr/local/php5./bin/php ...

  7. implode() 数组元素组合函数

    定义和用法 implode() 函数把数组元素组合为一个字符串. 语法:implode(separator,array); 说明 虽然 separator 参数是可选的.但是为了向后兼容,推荐您使用使 ...

  8. Rhino学习教程——1.1

    在Rhino的官网下载好Rhino5.0版本后(Rhino官网会提供下载方式,官网是http://www.xuexiniu.com),双击桌面快捷键,就会出现Rhino的界面(我已经自定义过界面了). ...

  9. unity中多个门的开关动画保持独立性

    List<Animation> storeAnimation; public void Awake() { storeAnimation = new List<Animation&g ...

  10. ACCESS 查询重复记录

    In (SELECT [全称] FROM [New14] As Tmp GROUP BY [全称],[账号],[银行] HAVING Count(*)>1  And [账号] = [New14] ...