January 2011
Intermediate to advanced
1648 pages
70h 30m
English
To justify our naming of finalizers over destructors, take a look in ILDASM at the generated code, as shown in Figure 12.6. As you can see, C# destructors get turned into methods that override the Finalize method, which is defined on System.Object. The user’s custom logic and a call to the base class’s finalizer live inside this method. Although we still have to learn about inheritance, the idea is simple. When a class derives from another one to specialize its behavior, it’s essential for the base class’s cleanup logic to run as part of finalization. The code in our finalizer will be equivalent to the following:
Figure 12.6. Destructors override the Finalize method.
Even though destructors turn into Finalize
Read now
Unlock full access