Why do I need to Dispose a System.Net.Mail.MailMessage instance?

后端 未结 2 783
失恋的感觉
失恋的感觉 2020-11-30 13:38

What unmanaged resources does it allocates that needs to be disposed? Isn\'t it just a simple array of managed data? So why disposing?

2条回答
  •  春和景丽
    2020-11-30 14:19

    A MailMessage can have attachments, an attachment is represented by MIME part which itself holds a Stream. This Stream needs closing as it might hold an unmanaged pointer to the underlying data.

提交回复
热议问题