What unmanaged resources does it allocates that needs to be disposed? Isn't it just a simple array of managed data? So why disposing?
The SmtpClient class has no Finalize method. So an application must call Dispose to explicitly free up resources.
Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The SmtpClient type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section.
A mail message has attachments -> attachments are Streams -> Streams are to be disposed.
Here is the decompiled Dispose method of MailMessage:
protected virtual void Dispose(bool disposing) { if (disposing && !this.disposed) { this.disposed = true; if (this.views != null) { this.views.Dispose(); } if (this.attachments != null) { this.attachments.Dispose(); } if (this.bodyView != null) { this.bodyView.Dispose(); } } }
As a general rule a class should implement IDisposable if any of its contained children implement it.
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