Out of curiosity i disassembled mscorlib.dll to check the implementation of System.Object class.
I found something weird in that.
1).
public class Object {
...
protected override void Finalize(){}
...
}
How come a base class has an overriden 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 am just wondering what's the use of "protected Finalize" method in Object class and why it has got special treatment by compiler?
It is a bug in Reflector, it gets confused by a method that's virtual but doesn't have the "newslot" attribute and doesn't have a base class type. It might be easier to see when you switch the decompiler to IL.
The real declaration of the finalizer, as copied from the Reference Source, is much as you'd expect it to be:
// Allow an object to free resources before the object is reclaimed by the GC.
//
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
~Object()
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With