20131026 garbage collection in .net framework
TRANSCRIPT
http://tech.tanaka733.net
http://www.buildinsider.net/web/iis8
http://metrostyledev.net/
Building a Faster Ruby Garbage Collector
Twitterが、Ruby on RailsからJavaVMへ移行する理由
Ruby 2.1がガベージコレクションを変更,大規模システムでの批判に対処
Garbage
Collection
ネイティブヒープ (OS)
仮想アドレス空間(GCセグメント)
.NET CLRが管理
32bitプロセス:1.5GB 近く、64bit: 8TB近くまで
マネージヒープ
Rocksee on Flickr viaESP
マーキング 再配置 コンパクション
空き 空き
空き 空き
空き
Ctd 2005 on Flickr viaESP
オブジェクトが新しいほど、生存期間は短い
オブジェクトが古いほど、生存期間は長い
ヒープの一部分の回収は、全体の回収より高速
gen 0 gen 1 gen 2
gen 0 gen 1 gen 2
gen 0 gen 1 gen 2
class MyClass{
~MyClass(){
//Finalizeメソッド}
}
James Cridland on Flickr viaESP
System.IDisposable
static void Main(string[] args){
FileStream fs = null;try{
fs = new FileStream("Temp.txt", FileMode.Create);fs.Write(new byte[]{1, 2, 3, 4}, 0 , 4);
}finally{
if (fs != null) { fs.Dispose(); }}
}
static void Main(string[] args){
using (var fs = new FileStream("Temp.txt", FileMode.Create))
{fs.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
}}
http://msdn.microsoft.com/ja-jp/library/fs2xkftw(v=vs.110).aspx
public void Dispose(){
Dispose(true);GC.SuppressFinalize(this);
}
http://msdn.microsoft.com/ja-jp/library/vstudio/ee851764(v=vs.110).aspx
プログラミング .NET Framework 第4版
http://msdn.microsoft.com/ja-jp/library/vstudio/hh156531(v=vs.110).aspx
C#プログラマのための.NETアプリケーション最適化技法
using