title: Memory Leak When SSL and Client Certificates Are Used With the HttpWebRequest Object
body: <p>I am using <code>HttpWebRequest</code> object to upload files using <code>SSL</code> with client certificate, I have a valid certificate on my server, My application is having a memory leak issue and Microsoft has posted something related to the issue on the following link:</p>
  
  <p><a href="http://support.microsoft.com/kb/831578" rel="noreferrer">FIX: Memory Leak When SSL and Client Certificates Are Used With the HttpWebRequest Object</a></p>
  
  <p>Is there any work around to avoid this memory leak specially that each request is consuming 8K leaked memory, this will cause my application to consume so much memory.</p>
  
  <hr>
  
  <pre><code> HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
   ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
   request.Method = "POST";
   request.ContentType = "text/xml; charset=utf-8";
  </code></pre>
  
  <hr>
  
  <p>memory leaks were detected using <a href="http://memprofiler.com/" rel="noreferrer">.NET Memory Profiler</a> and it shows the <code>HttpWebRequest</code> object has array of bytes that leaks the memory, I am deposing both stream and request objects.</p>
  
  <p>I have tried this case with <code>SSL</code> and <code>without SSL</code> the leaks have disappeared in non <code>SSL</code> Requests. </p>