Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET Objects

 AfterLogic Forum : MailBee.NET Objects
Subject Topic: Delete completed jobs Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Sergei
Newbie
Newbie


Joined: 27 September 2011
Online Status: Offline
Posts: 16
Posted: 26 October 2011 at 6:25am | IP Logged Quote Sergei

Hi, everyone. I encountered a problem: MailBee doesn't release memory after sending messages. Here is my situation:

I have a separate windows service, which monitors a message queue. Monitoring is done via separate thread. This thread initializes new instance of MailBee.SmtpMail.Smtp class and in a loop checks if a new message should be send and if there is a message then it takes one and send it by executing the following code:

mailer.AddJob(null, nextMessage, null, null);
mailer.SendJobs();

I do this because I want to be notified if a message was successfully sent or sending failed. Earlier I subscribe to MessageSent and MessageNotSent events and handle them.

The problem is, if I try to send a 100 emails and each of them is about 1mb I will see that windows service process consumes a lot of memory and that memory is never released.

By profiling memory I found that MailBee.SmtpMailJobCollection still holds SendMailJob instances which holds TextBodyPartCollection. That TextBodyPartCollection is the one that uses the memory.

I understand that these jobs contain my messages, but they contain them even if messages are already delivered.

I wanted to ask if I can do something about that? Should I dispose Smtp instance from time to time? Will it help and the memory will be released? Can I get the same effect without recreating Smtp instance?

Thanks in advance.
Back to Top View Sergei's Profile Search for other posts by Sergei
 
Sergei
Newbie
Newbie


Joined: 27 September 2011
Online Status: Offline
Posts: 16
Posted: 26 October 2011 at 7:38am | IP Logged Quote Sergei

Okay, it seems I found the solution:

After each success/failed sending I call:

mailer.JobsFailed.Clear();
mailer.JobsSuccessful.Clear();

That helps to release the memory, though I still not get the same values as before sending huge emails. But I believe it is CLR that doing that magic.
Back to Top View Sergei's Profile Search for other posts by Sergei
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 26 October 2011 at 9:33am | IP Logged Quote Alex

Best practice would be using Smtp.FinishingJob event. This way, you can opt it not to even put the completed job into JobsFailed or JobsSuccessful at all (using KeepIt property).

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
Sergei
Newbie
Newbie


Joined: 27 September 2011
Online Status: Offline
Posts: 16
Posted: 27 October 2011 at 6:50am | IP Logged Quote Sergei

Alex wrote:
Best practice would be using Smtp.FinishingJob event. This way, you can opt it not to even put the completed job into JobsFailed or JobsSuccessful at all (using KeepIt property).

Regards,
Alex


Thanks for the answer, Alex. I will take a look and see if I can subscribe to FinishingJob event and set KeepIt property to false.
Back to Top View Sergei's Profile Search for other posts by Sergei
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide