0 votes

We use Mail.dll to send emails and noticed a memory issue if we enable logging, the phenomenon is that memory use increases gradually and finally consumed full memory, we use DebugDialog tool to check memory and saw System.Char[] object consumed large memory.

First, we comment out the Limilabs.Mail.Log.WriteLine code(as we thought related to the way how we write log), but didn't work.
Then we comment out Limilabs.Mail.Log.Enabled = true; code to disable logging, the memory became to normal and didn't increase gradually anymore.

So I think this is an issue of how Mail.dll handles log content and didn't release things properly?

using Limilabs.Mail;
using Limilabs.Client.SMTP;

public void SendEmail()
{
    Log.Enabled = true;
    Log.WriteLine += LimilabsLog_WriteLine;

    using (Smtp smtp = new Smtp())
    {
        //...
    }
}

private void LimilabsLog_WriteLine(string line)
{
    //...
}
by

1 Answer

0 votes

With logging enabled every byte sent and received over the network is logged.

This means that large messages (including attachments) are converted to text form. It is expected that there will be large text objects stored for some short time in memory. There's nothing wrong with that.

Please note that .net garbage collector runs on a complex schedule and usually doesn't free up memory immediately, unless memory is needed.

by (301k points)
...