Public classtestclass:system.idisposable{//Dispose method for programmers to explicitly invoke Public voidDispose () {//call the Dispose method with parameters to release both managed and unmanaged resourcesDispose (true); //When you manually call Dispose to release the resource, the destructor is unnecessary, which prevents the GC from calling the destructorSystem.GC.SuppressFinalize ( This); } //the Dispose method of protected is guaranteed not to be called externally. //Pass in bool value disposing to determine whether to release managed resources protected voidDispose (BOOLdisposing) { if(disposing) {///TODO: Add the code that cleans up "managed resources" here, it should be xxx. Dispose (); } ///TODO: Add code to clean up "unmanaged resources" here } //destructors for GC calls~TestClass () {Dispose (false);//Releasing unmanaged Resources }}
C # GC