Author |
|
Sergei Newbie
Joined: 27 September 2011
Online Status: Offline Posts: 16
|
Posted: 26 October 2011 at 6:25am | IP Logged
|
|
|
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 |
|
|
Sergei Newbie
Joined: 27 September 2011
Online Status: Offline Posts: 16
|
Posted: 26 October 2011 at 7:38am | IP Logged
|
|
|
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 |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 26 October 2011 at 9:33am | IP Logged
|
|
|
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 |
|
|
Sergei Newbie
Joined: 27 September 2011
Online Status: Offline Posts: 16
|
Posted: 27 October 2011 at 6:50am | IP Logged
|
|
|
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 |
|
|