Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Gielovic  
#1 Posted : Tuesday, March 20, 2018 2:33:56 AM(UTC)
Gielovic

Rank: Newbie

Groups: Registered
Joined: 3/20/2018(UTC)
Posts: 2
Netherlands
Location: NL

When using the MailClient in a 'service-like' application where the operation can be paused and resumed, I would like to cleanup the MailClient. It does not release it's memory however. It seems like the MailInfo's (loaded with GetMailInfos()) are kept in memory. Simply creating a new instance and assigning it to a variable shows the same beviour.

I have tried using Close, Reset, and Quit but none of them seem to cleanup the memory. Also, there seems to be no documentation of what those operations intend to do exactly.

Any suggestions?

ivan  
#2 Posted : Thursday, March 22, 2018 5:06:20 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,148

Thanks: 9 times
Was thanked: 54 time(s) in 54 post(s)
Hi, are you using .NET class? You don't have to clean the memory manually, because .NET will collect garbage automatically, if your memory is enough, the memory won't be collected immediately.
Gielovic  
#3 Posted : Friday, March 23, 2018 3:33:44 AM(UTC)
Gielovic

Rank: Newbie

Groups: Registered
Joined: 3/20/2018(UTC)
Posts: 2
Netherlands
Location: NL

Yes I am using the .NET class. There appears to be some memory leak however. Perhaps some static reference holds on to some cached list of mailitems?.

Code:
                
/* Setup the server. */
oServer = new MailServer(settings);
/* Setup the client. */
oClient = new MailClient("key");
oClient.Connect(oServer);
var infos = oClient.GetMailInfos();
infos = null;
oClient.Quit(); oClient.Close();
// if garbage collection happens, we would expect the memory with al > 50.000 mailitems to be freed. 
oClient = new MailClient("key");
oClient.Connect(oServer);
var infos = oClient.GetMailInfos();
// at this moment, the memory footprint is doubled.


If we would do this multiple times (which is a realistic scenario if a service gets stopped and started several times), the memory used will only increase overtime.
ivan  
#4 Posted : Friday, March 23, 2018 5:51:20 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,148

Thanks: 9 times
Was thanked: 54 time(s) in 54 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

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.063 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.