The completion method in the System.Object class

Out of curiosity, I parsed mscorlib.dll to check the implementation of the System.Object class.

In this, I found something strange.

1).    
public class Object {
...
    protected override void Finalize(){}
...
}

Why does the base class have an overridden method in it?

2) public class Employee {
            public void InstanceMethod() {
                this.Finalize();
                //Does not compile, can i not access protected methods of base class??
            }
        }

I'm just wondering what is the use of the "protected Finalize" method in the Object class and why does it have special treatment with the compiler?

+3
source share
3 answers

Check MSDN on Object.Finalize :

- # . , . # Object.Finalize .

, : , CLR; # , , :

public class Employee
{
   //Finalizer, also known as "destructor"
   ~Employee()
   {

   }
}
0

Reflector, , , "newslot" . , IL.

, , , :

// Allow an object to free resources before the object is reclaimed by the GC.
//
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
~Object()
{
}
+4

# ~MyClass VB.NET Protected Overrides Sub Finalize(), protected override Finalize(). #.

Reflector

.method family hidebysig virtual instance void Finalize() cil managed

which lacks an attribute newslotthat is usually displayed on new virtual elements compared to overrides.

+1
source

Source: https://habr.com/ru/post/1729682/


All Articles