Only one of the three ways to implement a destructor that you list actually involves a destructor, and that's ~Destructor()
.
If you implement IDisposable
, and dispose of your object, then the code in Dispose
will run, but there's no reason to think that your destructor will.
I think you chasing the impossible here. Destructors run as and when the garbage collector so decrees. It's not something that you have any control over. The GC is well within its rights to form the opinion that running destructors simply wastes time, and if there is plenty of memory it will form that opinion.
If you need predictable disposal, finalization etc., then use IDisposable
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…