Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dispose Class Resources

Tags:

c#

I have the following class:

public class MailData : IDisposable
{
  public IDictionary<String, Tuple<Byte[], String>> Attachments { get; set; }
  public String From { get; set; }
  public IList<String> To { get; set; }   
  public MailType Type { get; set; }
} // MailData

What would be the correct way to dispose the class?

I mean, I think I should remove all Byte[] from Dictionary ...

What about the other properties?

like image 570
Miguel Moura Avatar asked May 11 '26 10:05

Miguel Moura


1 Answers

.NET is a managed environment and you have to allow the Garbage Collector to do it's job, there is no reason for you to dispose simple reference classes and byte[] is still a reference.

Usually you use the Dispose pattern to let go of valuable resources such as file I/O, various Streams, database connections...etc

In your case however, there is no need to do anything on your own.

Welcome to the managed world of C#.

like image 57
Stan R. Avatar answered May 13 '26 00:05

Stan R.