C# Finalize方法
声明destructor
1 public class Test
2 {
3 ~Test()
4 {
5 }
6 }
7
2 {
3 ~Test()
4 {
5 }
6 }
7
编译后的MSIL代码
1 .method family hidebysig virtual instance void
2 Finalize() cil managed
3 {
4 // Code size 16 (0x10)
5 .maxstack 1
6 .locals init ([0] int32 a)
7 .try
8 {
9 IL_0000: nop
10 IL_0001: ldc.i4.0
11 IL_0002: stloc.0
12 IL_0003: nop
13 IL_0004: leave.s IL_000e
14 } // end .try
15 finally
16 {
17 IL_0006: ldarg.0
18 IL_0007: call instance void [mscorlib]System.Object::Finalize()
19 IL_000c: nop
20 IL_000d: endfinally
21 } // end handler
22 IL_000e: nop
23 IL_000f: ret
24 } // end of method Test::Finalize
25
26
2 Finalize() cil managed
3 {
4 // Code size 16 (0x10)
5 .maxstack 1
6 .locals init ([0] int32 a)
7 .try
8 {
9 IL_0000: nop
10 IL_0001: ldc.i4.0
11 IL_0002: stloc.0
12 IL_0003: nop
13 IL_0004: leave.s IL_000e
14 } // end .try
15 finally
16 {
17 IL_0006: ldarg.0
18 IL_0007: call instance void [mscorlib]System.Object::Finalize()
19 IL_000c: nop
20 IL_000d: endfinally
21 } // end handler
22 IL_000e: nop
23 IL_000f: ret
24 } // end of method Test::Finalize
25
26