Finalize方法的生成

Finalize在c#编程语言中需要特殊语法,因此,c#要求在类名前加~符号来定义Finalize方法:例如

internal class FinalizeDemo
{
~FinalizeDemo()
{
int num = GC.MaxGeneration;
}
}

ILDasm.exe所在目录

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools

使用ILDasm.exe查看Finalize生成的中间语言

.method family hidebysig virtual instance void
Finalize() cil managed
{
.override [mscorlib]System.Object::Finalize
// 代码大小 19 (0x13)
.maxstack 1
.locals init ([0] int32 num)
IL_0000: nop
.try
{
IL_0001: nop
IL_0002: call int32 [mscorlib]System.GC::get_MaxGeneration()
IL_0007: stloc.0
IL_0008: leave.s IL_0012
} // end .try
finally
{
IL_000a: ldarg.0
IL_000b: call instance void [mscorlib]System.Object::Finalize()
IL_0010: nop
IL_0011: endfinally
} // end handler
IL_0012: ret
} // end of method FinalizeDemo::Finalize

  

上一篇:GDI+_从Bitmap里得到的Color数组值分解


下一篇:mongoose学习笔记1--基础知识1