Process leaks memory. Am I using ImapX incorrectly?

Topics: Help requests
Apr 13, 2016 at 10:05 AM
Edited Apr 13, 2016 at 10:06 AM
When I tried to run application with this code
client.Behavior.MessageFetchMode = MessageFetchMode.Headers;
client.Behavior.AutoPopulateFolderMessages = true; 

ImapX.Folder myInbox = client.Folders.Inbox;

foreach (ImapX.Message currentMessage in myInbox.Messages)
{
    currentMessage.Download(MessageFetchMode.Full, false);
    //...............
    foreach (Attachment file in currentMessage.Attachments)
    {
        try
        {
            string curFileName = getFreeFileName(file.FileName);
            file.Save(AttachesStoragePath, curFileName);
            //.............................
        }
        catch (Exception ex)
        {
            //.............................
        }
    }
    saveMailMessageToDb(UID, From, Subject, Date, filenamesList, AttachesStoragePath, Body, errorsList);
}
it fills more and more memory, and not release it in the end. If there's too many messages at a mail server, process throws outOfMemory exception.