title: How do I properly dispose the byte array used in the class?
body: <p>I have a StateObject class which is being used to store the data from client and server. </p>
  
  <p>Here is the code:</p>
  
  <pre><code> public class StateObject : IDisposable 
      {
          public StateObject()
          {
  
          }
  
          public String serviceName = ConfigurationManager.AppSettings["ServiceName"].ToString().Trim();  //Holds the service name 
          public Socket clientSocket; //socket for communication with the client
  
          public int id; //client id  (A running sequence to keep track of StateObjects)
  
          public string leaseId; //holds the leaseId that is used to communicate with the server
  
          public bool isLeaseIdValid = false;
  
          public string requestQuery = string.Empty;
  
          public IPEndPoint serverEP;
  
          public Socket serverSocket; //Socket for communication with the server
  
          public static int BUFFER_SIZE = Convert.ToInt32(ConfigurationManager.AppSettings["BufferSize"].ToString().Trim());  //Get the buffer size from the state object
  
          public byte[] clientReadBuffer = new byte[BUFFER_SIZE];   // Receive clientReadBuffer.
          public byte[] serverReadBuffer = new byte[BUFFER_SIZE];
  
          public int clientNumBytes;
          public byte[] clientSendBuffer = new byte[BUFFER_SIZE];
          public int serverNumBytes;
          public byte[] serverSendBuffer = new byte[BUFFER_SIZE];
  
          public bool isShutdown = false;
  
          public Socket serverSocketPort80; //Socket for communication with the server
  
          public bool ConnectedToPort80 = false; //initially set to false
  
          public ConnectionObject connectionObject;
  
          #region Dispose implementation
  
          public void Dispose()
          {
              Dispose(true);
              GC.SuppressFinalize(this);
          }
  
          protected virtual void Dispose(bool disposing)
          {
              if (disposing)
              {
                  connectionObject.Dispose();
              }
          }
  
          ~StateObject()
          {
              Dispose(false);
          }
  
          #endregion
      }
  </code></pre>
  
  <p>How do I properly dispose this class and clearup the memory used by the byte array ? The byte arrays are being used to store sent/received messages in a socket communication.</p>