Author |
|
loredano Newbie
Joined: 11 April 2018 Location: Italy
Online Status: Offline Posts: 15
|
Posted: 27 November 2018 at 12:09am | IP Logged
|
|
|
Hi,
We have a list of entity that contains also the mailmessage. Then after inserting the data of 500 mails in the database, we select the id, the name of the email, the destination folder, the messageid; put these data in a datareader and (while) for each element in the datareader we use the method Save of the object mail message found in the list. But after 420 iterations on datareader we obtain a mailbee exception of outofmemory.
Is better use smtp object and use submit to pickup folder for every item?
This a fragment of code.
while (dr.Read())
{
id = dr.GetInt64(0);
currmessage = lstMessages.FirstOrDefault(oe => oe.Id == id);
pathEml = dr["PathEml"].ToString();
try
{
if (!currmessage.Msg.SaveMessage(pathEml))
{
messageSaved = false;
break;
}
}
}
.......................
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 27 November 2018 at 1:14am | IP Logged
|
|
|
Hi,
You need to free MailMessage objects (e.g assign to null all pointers to the MailMessage object in question) immediately after they are no longer needed. This is not just for MailBee, it's the standard approach of avoiding memory leaks.
I guess lstMessages holds all the pointers and grows to storing 500 fully built emails in memory at the same time.
try
{
if (!currmessage.Msg.SaveMessage(pathEml))
{
messageSaved = false;
break;
}
currmessage.Msg = null;
}
Regards,
Alex
|
Back to Top |
|
|