.Net memory management Learning Notes
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的更多相关文章
- Operating System Memory Management、Page Fault Exception、Cache Replacement Strategy Learning、LRU Algorithm
目录 . 引言 . 页表 . 结构化内存管理 . 物理内存的管理 . SLAB分配器 . 处理器高速缓存和TLB控制 . 内存管理的概念 . 内存覆盖与内存交换 . 内存连续分配管理方式 . 内存非连 ...
- Obj-C Memory Management
Memory management is one of the most important process in any programming language. It is the proces ...
- Memory Management in Open Cascade
Open Cascade中的内存管理 Memory Management in Open Cascade eryar@163.com 一.C++中的内存管理 Memory Management in ...
- Java (JVM) Memory Model – Memory Management in Java
原文地址:http://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java Understanding JV ...
- Objective-C Memory Management
Objective-C Memory Management Using Reference Counting 每一个从NSObject派生的对象都继承了对应的内存管理的行为.这些类的内部存在一个称为r ...
- 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- ...
- 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 ...
- Understanding Memory Management(2)
Understanding Memory Management Memory management is the process of allocating new objects and remov ...
- Java Memory Management(1)
Java Memory Management, with its built-in garbage collection, is one of the language’s finest achiev ...
随机推荐
- python -- 函数进阶
一.函数参数-动态传参 1.形参: * 在形参位置, 表示此参数为不定参数,接受的是位置参数 并且接收到的位置参数的动态传参都是元组 def fu ...
- There are multiple modules with names that only differ in casing. 黄色warning
There are multiple modules with names that only differ in casing.有多个模块同名仅大小写不同This can lead to unexp ...
- PHP设置凌晨时间戳
这种需求应是很常见的,但一直没有时间整理. 一天可以领取2次奖励,今天领完了那就等明天再来. 这里面涉及到一个很重要的一点就是凌晨12点的时间戳,以前一直在前端去做判断.最近发现在后端用PHP获取凌晨 ...
- redis最全配置讲解
#redis.conf# Redis configuration file example.# ./redis-server /path/to/redis.conf ################# ...
- PROJ.4学习——初识PROJ
PROJ.4介绍——初始认识 前言 PROJ是一个通用的坐标转换软件,它将地理空间坐标从一个坐标系转换为另一个坐标系.这包括地图投影和大地坐标变换. PROJ包含命令行应用程序,可以方便地从文本文件或 ...
- nginx常用模块
Nginx模块介绍 核心模块:core module 标准模块:stand modules HTTP modules: Standard HTTP modules Optional HTTP modu ...
- javascript--返回顶部效果
window.onload = function(){ var obtn = document.getElementById('btn'); //客户端页面可视区高度 var clientHeight ...
- jQuery对象与DOM对象互相转换
1.jQuey对象转DOM对象 a. [index] 代码如下: var $a = $("#a"); //jQuery对象 var a = $a[]; //DOM对象 b. g ...
- lunx中部分命令总结
一.文件和目录操作命令ls 全拼list,功能是列出目录的内容及其内容属性信息. cd 全拼change directory,功能是从当前工作目录切换到指定的工作目录. cp 全拼copy,其功 ...
- docker学习构建镜像---第三章节
一.docker镜像使用 运行docker容器时,使用的镜像如果在本地不存在,docker会自动从docker镜像仓库中下载,默认是从docker hub公共镜像源下载 在这里,我们需要了解:管理和使 ...