It turns out that I use MemoryStream
to read a file with ReadToEnd
in the following way:
IEnumerable<uint> uids = Client.Search(SearchCondition.Unseen());
IEnumerable<MailMessage> messages = Client.GetMessages(uids, FetchOptions.Normal);
foreach (MailMessage msg in messages){
foreach (Attachment atc in msg.Attachments){
byte[] allBytes = new byte[msg.Attachments[0].ContentStream.Length];
int bytesRead = msg.Attachments[0].ContentStream.Read(allBytes, 0, (int)msg.Attachments[0].ContentStream.Length);
MemoryStream memory = new MemoryStream(allBytes);
System.IO.StreamReader archivoXML = new System.IO.StreamReader(memory);
memory.Close();
String archivoXML_texto = archivoXML.ReadToEnd();
archivoXML.Close();
}
}
Because of this, I have the concern that in memory there could be several garbage files. If so, I would like to know how to erase or clean the memory of these files after reading them, where they are obtained with MemoryStream
.
Observation: I read the attachment from an email using the IMAP protocol, and not from a saved route.
Observation 2: When using this instruction, read me content, if not, the variable XMLX_text stored empty:
int bytesRead = msg.Attachments[0].ContentStream.Read(allBytes, 0, (int)msg.Attachments[0].ContentStream.Length);