When I write a mail delivery service, I find the 'Dispose()' function:
private void InnerDisposeMessage(MailMessage message)
{
if (message != null)
{
if (message.AlternateViews.Count > 0)
{
message.AlternateViews.Dispose();
}
message.Dispose();
message = null;
}
}
And I track to the Dispose()
function(message.AlternateViews.Dispose();)
, here it is:
public void Dispose()
{
if (!this.disposed)
{
foreach (AlternateView view in this)
{
view.Dispose();
}
base.Clear();
this.disposed = true;
}
}
And I track to the view.Dispose() function, here it is:
protected virtual void Dispose(bool disposing)
{
if (disposing && !this.disposed)
{
this.disposed = true;
this.part.Dispose();
}
}
And I track to the this.part.Dispose(); function, here it is:
public void Dispose()
{
if (this.stream != null)
{
this.stream.Close();
}
}
And I track to the stream:
public virtual void Close()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
and the SuppressFinalize:
public static void SuppressFinalize(object obj)
{
if (obj == null)
{
throw new ArgumentNullException("obj");
}
_SuppressFinalize(obj);
}
But how the resource to be released? I just understand to invoke the Garbage Collection to release, but how?
I know this question is not easy to understand, but I just want to try!
What the GC.SuppressFinalize(this) function do?