B
Bob
When implementing the Dispose() method, I understand that it's supposed to
do what Finalize() does so that's why it should call GC.SuppressFinalize().
However, it's not clear to me what happens the instance itself, for example
in the following code:
public class Test1 : IDisposable {
public string Hello() {
return "HEllo";
}
public void Dispose() {
System.Diagnostics.Debug.WriteLine("This is disposed");
GC.SuppressFinalize(this);
}
}
I don't see how an instance of this class can be destroyed as there is not
something like "this = null;" in Dispose(), and also Finalize() won't be
called. Does the runtime somehow know that the instance of this class has a
Dispose() method so it should go ahead destroy the instance once the
Dispose() method is called??
do what Finalize() does so that's why it should call GC.SuppressFinalize().
However, it's not clear to me what happens the instance itself, for example
in the following code:
public class Test1 : IDisposable {
public string Hello() {
return "HEllo";
}
public void Dispose() {
System.Diagnostics.Debug.WriteLine("This is disposed");
GC.SuppressFinalize(this);
}
}
I don't see how an instance of this class can be destroyed as there is not
something like "this = null;" in Dispose(), and also Finalize() won't be
called. Does the runtime somehow know that the instance of this class has a
Dispose() method so it should go ahead destroy the instance once the
Dispose() method is called??