Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
|
There is a list in MailClient to keep the MailInfo cache, but MailClient will free it automatically, but .NET GC doesn't work like Native C++, it doesn't free the memory immediately. I just did a test like this: Code:
for (int i = 0; i < 1000; i++)
{
var server = new MailServer("server address", "user", "password", ServerProtocol.Imap4);
server.SSLConnection = true; // i also tested other protocols.
server.Port = 993;
var client = new MailClient("TryIt");
client.Connect(server);
var infos = client.GetMailInfos(); // here is 87940 emails
Console.WriteLine("Total {0} {1} emails", i, infos.Length);
client.Quit();
// Collect all generations of memory.
GC.Collect();
Console.WriteLine("Memory used after full collection: {0:N0}",
GC.GetTotalMemory(true));
}
here is output, from the output, GetMailInfo doesn't have memory leak, i also reviewed the source codes, it used pure manage resource in GetMailInfos. Code:
Total 17 87940 emails
Memory used after full collection: 41,091,104
Total 18 87940 emails
Memory used after full collection: 41,090,640
Total 19 87940 emails
Memory used after full collection: 41,091,104
Total 20 87940 emails
Memory used after full collection: 41,091,104
Total 21 87940 emails
Memory used after full collection: 41,091,128
Total 22 87940 emails
Memory used after full collection: 41,091,104
Total 23 87940 emails
Memory used after full collection: 41,091,128
Total 24 87940 emails
Memory used after full collection: 41,091,104
Total 25 87940 emails
Memory used after full collection: 41,091,592
Total 26 87940 emails
Memory used after full collection: 41,091,128
Total 27 87940 emails
Memory used after full collection: 41,091,104
Total 28 87940 emails
Memory used after full collection: 41,090,640
If i don't use GC.Collect(); it used about 48MB - 160MB, but it never exceed to upper bound, hope this could be helpful to you. Edited by user Friday, March 23, 2018 7:13:28 PM(UTC)
| Reason: Not specified
|