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. STL 小白学习(7) list

    #include <iostream> using namespace std; #include <list> void printList(list<int>& ...

  2. sqlserver数据库 视图相关

    1.首先创建一个视图 方法一:右键解决 方法二:脚本 create view view_test AS select * from t1 GO 2.删除视图 方法1:右键解决 方法2:脚本 if ex ...

  3. 关于SASS

    SASS:(是一款辅助编写css的工具 安装之后可以通过同时按window键+“R”键 输入“powershell”进入CMD命令页面: 输入“sass -v”可以查看当前的sass版本 输入“cd ...

  4. 编码 decode & encode

    import sys # python3 中字符编码默认为 utf-8 s = '你好' print(s) # utf-8 转为 gbk (s 默认为 unicode 所以可以直接 encode 成 ...

  5. add

    前台 <input id="Button1" type="button" value="button" onclick="a ...

  6. [NOIP2013D1]

    T1 Problem 洛谷 Solution 感觉我写的也不是正解... 我是先找出每个循环节的长度l...然后用快速幂求出10 ^ k % l的值.. Code #include<cmath& ...

  7. react-redux-数据流

    redux是严格的单向数据流 1,store.dispatch(action) 2, reducer(previousState, action), reducer是纯函数.它仅仅用于计算下一个 st ...

  8. saltstack高效运维

    saltstack高效运维   salt介绍 saltstack是由thomas Hatch于2011年创建的一个开源项目,设计初衷是为了实现一个快速的远程执行系统. salt强大吗 系统管理员日常会 ...

  9. Oracle数据库字段数据拆分成多行(REGEXP_SUBSTR函数)

    做多选功能时为了简便,会在某个字段中存储多个值,保存时虽然省事,但后续的查询统计时还需要拆分数据才行,因此这时需要将字段内的值分成多行以便后续使用. 下面这个例子实现了字段内数据的拆分: --创建测试 ...

  10. 记一次 SSM 分页

    1.实体层(entity,pojo,domain) package com.entity; import java.io.Serializable; private int totalCount; / ...