OutOfMemory exception at rush-hours

Hi,


I use Aspose.Email to process messages coming through Exchange environment. Some times I get OutOfMemory exceptions opening message with MailMessage class at rush-hours.

I understand, that it is not only Aspose.Email who consumes memory of the process. But I noticed that Aspose.Email eats 300 MB of RAM to open 71 MB message with 2 attachments.

Is there any chance that dev team will take a look at the logic in order to reduce memory consumption?

Attached sample EML file.

Thanks,
Alex Shoma

Hi Alex,


Thank you for writing to Aspose support team.

We have tested your sample file with the latest version of Aspose.Email for .NET 5.9.0 and it doesn’t raise any exception. We already have a ticket logged as EMAILNET-35009 in our issue tracking system for memory problems when Aspose.Email loads messages using MailMessage. This issue will be fixed in Aspose.Email for .NET 6.0.0. I have linked this thread with the logged ticket and we shall update you here once there is some information available about this problem.

Hi,


Do you have any update on this?

I tested on Aspose.Email 6.5.0. Process consumes 541 MB of memory to read 174 MB EML message containing 121 MB PDF. When the workload of our system increases it periodically gets OutOfMemoryException:

Here is a stack trace for one of these exceptions. Sometimes it happens on MailMessage.Load method.

Type: System.OutOfMemoryException.
StackTrace:
at System.Convert.ToBase64String(Byte[] inArray, Int32 offset, Int32 length, Base64FormattingOptions options)
at #=qiJT7PFSD9NZK2_oD2dBie5n9n3YOD6msVns95rLkSsA=.#=qImLXasWLlKGdOb_xfN7nwQ==(Byte[] #=qTaoGYgdlbUYDB7kPRxf6kA==, Int32 #=qrVNQNVod3OjrGd$YFkKqug==, Int32 #=qUwmgPbCWMe3XLIHAJUoNcA==)
at #=qiJT7PFSD9NZK2_oD2dBie5n9n3YOD6msVns95rLkSsA=.Write(Byte[] #=qTaoGYgdlbUYDB7kPRxf6kA==, Int32 #=qrVNQNVod3OjrGd$YFkKqug==, Int32 #=qUwmgPbCWMe3XLIHAJUoNcA==)
at #=q8cQyU70huWJJAqXEevXBJLR_k7cHaxZhAjo3CILqpW8=.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==, Boolean #=qFRownCxHx80cHqdMZL25KA==)
at #=q6khB8xrs9cEcjSPoWDZiBbqWGYYrXSe6PD4WRJI4sEc=.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==)
at Aspose.Email.Mail.MailMessage.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==)
at Aspose.Email.Mail.MailMessage.Save(Stream stream, SaveOptions options)
at Aspose.Email.Mail.MailMessage.Save(Stream stream)
at Aspose.Email.Mail.MailMessage.#=qP0iXsZsAa4abliggZZYi0Q==(Stream #=qAUN5vSyAuH4luftw6oGC8Q==)
at Aspose.Email.Mail.MailMessage.Save(Stream stream, SaveOptions options)

Another example
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at #=qsddo_i7cctqF11h0iktnYZLn$kw$3Gt7n9I0HT6Tv7o=.Write(Byte[] #=qCIMLA9w8JZpAPQNcMqx3aw==, Int32 #=qrVNQNVod3OjrGd$YFkKqug==, Int32 #=qUwmgPbCWMe3XLIHAJUoNcA==)
at #=qtiFt5PCzkcDMOfAdG8zivpUUf9czNKy3lLkFaeKUtQU=.#=qJjMFJxvJqzgSMKhIUMZFAw==(Stream #=qSxfTRs1VoN1keWt1K4zjbw==, Stream #=q$tqHGIUVxRREqkB02iWCec_f6OLL7$XAA09LNuqFU5c=)
at #=q4uwVnuLC1ayRpzDK8QZevvLpCl2rLEpJ1z0cJ4LDA3tKpOUZitEHOsYfKQuOoPfp.#=qO5vQCDgYkHQz71Lf7InXeQ==(Stream #=qmnavCr5gNl5rEozyM4jQ7Q==, HeaderCollection #=qG5SgC4lwcwrWZYqpwlLe0A==)
at #=q4uwVnuLC1ayRpzDK8QZevvLpCl2rLEpJ1z0cJ4LDA3tKpOUZitEHOsYfKQuOoPfp.#=q0IY$ok6U6gLyIlI0pUux4Q==(Byte[] #=qIBsIxsAvl_AIw0E3j44Hio5$c$JxsUx$n4C4tpyG2R4=, Collection1 #=qTRMFehHyzvmK6HVuwsLiQA==)</font></div><div><font face="Tahoma" size="2"> at #=q4uwVnuLC1ayRpzDK8QZevvLpCl2rLEpJ1z0cJ4LDA3tKpOUZitEHOsYfKQuOoPfp.#=q0IY$ok6U6gLyIlI0pUux4Q==(Byte[] #=qIBsIxsAvl_AIw0E3j44Hio5$c$JxsUx$n4C4tpyG2R4=, Collection1 #=qTRMFehHyzvmK6HVuwsLiQA==)
at #=q4uwVnuLC1ayRpzDK8QZevvLpCl2rLEpJ1z0cJ4LDA3tKpOUZitEHOsYfKQuOoPfp.#=qvJxCzXhN0kXgsIafmYq35l32jZWl9iUCLFnzKuLGZno=()
at Aspose.Email.Mail.MailMessage.#=q2Wva4gkFB9kHYOkA4I78uA==(Stream #=qAUN5vSyAuH4luftw6oGC8Q==, EmlLoadOptions #=q6uW9PVCTPCgTVeRj50107Q==)
at Aspose.Email.Mail.MailMessage.#=qSAN0hHJW66M4APkGbAG879OHuMSDrfXNQI$K_BPgB6Y=(Stream #=qAUN5vSyAuH4luftw6oGC8Q==, LoadOptions #=q6uW9PVCTPCgTVeRj50107Q==)
at Aspose.Email.Mail.MailMessage.Load(String fileName, LoadOptions options)



Hi,


Thank you for sharing your concern.

The above mentioned issue had already been fixed in Aspose.Email for .NET 6.0. However, we have another issue logged as EMAILNET-35246 in our issue tracking system where we faced out of memory exception while working with large size messages. Our product team is still working on this problem and it is pending for resolution yet. We’ll update you here once there is more information available in this regard.

Hi,


Want to share with you, that since I started to use Aspose.Email 6.5.0, I have been reported about OutOfMemory exceptions 6 times in a short period of time bu customers.

Not a good signal if it continue in this way.

Would be good to get some update on this issue if any.

Type: System.OutOfMemoryException.
StackTrace:
at System.Convert.ToBase64String(Byte[] inArray, Int32 offset, Int32 length, Base64FormattingOptions options)
at #=qiJT7PFSD9NZK2_oD2dBie5n9n3YOD6msVns95rLkSsA=.#=qImLXasWLlKGdOb_xfN7nwQ==(Byte[] #=qTaoGYgdlbUYDB7kPRxf6kA==, Int32 #=qrVNQNVod3OjrGd$YFkKqug==, Int32 #=qUwmgPbCWMe3XLIHAJUoNcA==)
at #=qiJT7PFSD9NZK2_oD2dBie5n9n3YOD6msVns95rLkSsA=.Write(Byte[] #=qTaoGYgdlbUYDB7kPRxf6kA==, Int32 #=qrVNQNVod3OjrGd$YFkKqug==, Int32 #=qUwmgPbCWMe3XLIHAJUoNcA==)
at #=q8cQyU70huWJJAqXEevXBJLR_k7cHaxZhAjo3CILqpW8=.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==, Boolean #=qFRownCxHx80cHqdMZL25KA==)
at #=q6khB8xrs9cEcjSPoWDZiBbqWGYYrXSe6PD4WRJI4sEc=.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==)
at Aspose.Email.Mail.MailMessage.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==)
at Aspose.Email.Mail.MailMessage.Save(Stream stream, SaveOptions options)
at Aspose.Email.Mail.MailMessage.Save(Stream stream)
at Aspose.Email.Mail.MailMessage.#=qP0iXsZsAa4abliggZZYi0Q==(Stream #=qAUN5vSyAuH4luftw6oGC8Q==)
at Aspose.Email.Mail.MailMessage.Save(Stream stream, SaveOptions options)



Type: System.OutOfMemoryException.
StackTrace:
at System.IO.MemoryStream.set_Capacity(Int32 value) at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at #=q7B_ikgtsQHfLEK$7Ys8aPbAq3zeYiymHtdQvN$kA_88=.Write(Byte[] #=qTaoGYgdlbUYDB7kPRxf6kA==, Int32 #=qrVNQNVod3OjrGd$YFkKqug==, Int32 #=qUwmgPbCWMe3XLIHAJUoNcA==) at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at System.IO.StreamWriter.Write(String value)
at #=qiJT7PFSD9NZK2_oD2dBie5n9n3YOD6msVns95rLkSsA=.Write(Byte[] #=qTaoGYgdlbUYDB7kPRxf6kA==, Int32 #=qrVNQNVod3OjrGd$YFkKqug==, Int32 #=qUwmgPbCWMe3XLIHAJUoNcA==)
at #=q8cQyU70huWJJAqXEevXBJLR_k7cHaxZhAjo3CILqpW8=.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==, Boolean #=qFRownCxHx80cHqdMZL25KA==)
at #=q6khB8xrs9cEcjSPoWDZiBbqWGYYrXSe6PD4WRJI4sEc=.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==)
at Aspose.Email.Mail.MailMessage.#=qegc1BfnvqfZwtuWSGGLBCQ==(#=qV2HCXJu0eFzVLWC251TxDYEJ7VNGwJyNHwfgQ6PqUfk= #=q$JmDeGZp8pRtXm$0356AWw==)
at Aspose.Email.Mail.MailMessage.Save(Stream stream, SaveOptions options)
at Aspose.Email.Mail.MailMessage.Save(Stream stream)
at Aspose.Email.Mail.MailMessage.#=qP0iXsZsAa4abliggZZYi0Q==(Stream #=qAUN5vSyAuH4luftw6oGC8Q==)
at Aspose.Email.Mail.MailMessage.Save(Stream stream, SaveOptions options)


Type: System.OutOfMemoryException.
StackTrace:
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at #=qFMhqCa5jK1Oo_iER8jZj40F0mGfJ9toXpwb$iVCdKUg=.#=qit3bcIt6ByISckcx$YNutV$LKZMJyVfctnJMiwJpAhk=(Stream #=qF7WyZl9U$$$KXFnaRQkgNw==)
at #=q8cQyU70huWJJAqXEevXBJLR_k7cHaxZhAjo3CILqpW8=.#=qzXvJ5P3335BgfeApu0AqbA==()
at Aspose.Email.Mail.Attachment.#=qzXvJ5P3335BgfeApu0AqbA==() at Aspose.Email.Mail.MailMessage.Clone()
at Aspose.Email.Mail.MailMessage.#=qP0iXsZsAa4abliggZZYi0Q==(Stream #=qAUN5vSyAuH4luftw6oGC8Q==)
at Aspose.Email.Mail.MailMessage.Save(Stream stream, SaveOptions options)

Hi,

Please try the latest version of the API as well i.e. Aspose.Email for .NET 6.7.0. Also, please share with us your exact meaning by “Rush-hours” so that we can add this information against the logged ticket. If possible, please share few sample files with us that give raise to this issue. We’ll provide these as well with the logged ticket for further consideration. Once the new release is available for download, we’ll also update you here so that you can test the problem with the new version as well.

It was used in the initial post.

A rush hour (peak hour) is a part of the day during which email traffic is at its highest (like traffic on a road) - so many emails are processed simultaneously.

With build 6.5.0 we get OutOfMemory occurs even in situation when 2-3 emails are processed if some of them contain big attachment(s) like 100 MB PDF.

Thanks,
Alex
Do not have sample files from customers. Here is my own test with Aspose.Email 6.5.0.

"121 745 777.dat" any 121 MB file.

OutOfMemory is thrown at different time depending on the amount of system resources available for a process.

for (int j = 0; j < 3; j++)
{
new Thread(() =>
{
for (int i = 0; i < 10; i++)
{
using (var m = MailMessage.Load(@"d:\with huge pdf.eml", new EmlLoadOptions()))
{

m.Attachments[0].ContentStream = File.OpenRead(@"d:\121 745 777.dat");

m.Save(@"d:\with huge pdf-resaved_" + new Random().Next(250005) + ".eml",
new EmlSaveOptions(MailMessageSaveType.EmlFormat)
{
FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments
});
}
}

}).Start();
}

Thread.Sleep(555555);

Thanks,
Alex

Hi Alex,


Thank you for sharing the sample file.

Since one such issue is already logged as EMAILNET-35246 in our issue tracking system, we’ll request you to wait for resolution of this ticket and test the problem again at your end. We’ll notify you here once the fix version is available for the logged ticket.

Hi,


I’ve got another OutOfMemoryException. This time it was thrown in SmtpClient.Forward method. No pressure, I know that you have already openeded ticket for OutOfMemoryException. I’m informing you about this instance, because it is in a different part of API, so that you were aware of another place to look at.

Message size was ~130 MB.

Stack trace:

at System.Convert.ToBase64String(Byte[] inArray, Int32 offset, Int32 length, Base64FormattingOptions options)
at #=qiyLH8_STFGEOuFnDS$6a6KqQ4Gnzpx65JWTWXcsZjcw=.#=qkYo8ZsDB0wqS_mvuGgFUKw==(Byte[] #=qaFRFFv4DoBVAhBFb$_w4OA==, Int32 #=qtRy3g$nQLBiBElK4MaSHTA==, Int32 #=qcdwyQ4x1lNPBYTifq5gx0g==)
at #=qiyLH8_STFGEOuFnDS$6a6KqQ4Gnzpx65JWTWXcsZjcw=.Write(Byte[] #=qaFRFFv4DoBVAhBFb$_w4OA==, Int32 #=qtRy3g$nQLBiBElK4MaSHTA==, Int32 #=qcdwyQ4x1lNPBYTifq5gx0g==)
at #=qLz3uurYWDXLgWEFICf9oiCM2tW8lzapxGtEs6BMbMKc=.#=ql3oFSjYN0x40AEXmJRlD1w==(#=qwf8_dALK5bF$K_x$nwrNet2QmFBFzsFueOktFOelXnQ= #=qJ3AMaR2bjWaiVKSIYFMHNw==, Boolean #=qIq9U7nFZpZBu3SzUHcaLnw==)
at #=qVvOU6V$BazMH4QhKjDtN6q3qHBHIYmJ1Mf9D0UBaWCdN015h6Ss8wFqTOKEH7wED.#=ql3oFSjYN0x40AEXmJRlD1w==(#=qwf8_dALK5bF$K_x$nwrNet2QmFBFzsFueOktFOelXnQ= #=qJ3AMaR2bjWaiVKSIYFMHNw==, Boolean #=qIq9U7nFZpZBu3SzUHcaLnw==)
at #=qiuGoEfw_MjSaDNBdCD$ttDdCVH0xrR5SkPv5U6uNFGs=.#=ql3oFSjYN0x40AEXmJRlD1w==(#=qwf8_dALK5bF$K_x$nwrNet2QmFBFzsFueOktFOelXnQ= #=qJ3AMaR2bjWaiVKSIYFMHNw==)
at Aspose.Email.Mail.MailMessage.#=ql3oFSjYN0x40AEXmJRlD1w==(#=qwf8_dALK5bF$K_x$nwrNet2QmFBFzsFueOktFOelXnQ= #=qJ3AMaR2bjWaiVKSIYFMHNw==)
at Aspose.Email.Mail.SmtpClient.#=q$OadZccYZrtvYR3z5mJiQA==(IConnection #=qy1o4vNg7CpaSyWrRN4LuDA==, MailAddress #=qhUOqaa5qsoWb2wysTQFAew==, MailAddressCollection #=qk70NPmcbGL7GMFJ8AL9eig==, MailMessage #=qA1yfj_nizKiPBPCQYi_Ucg==)
at Aspose.Email.Mail.SmtpClient.Forward(IConnection iConnection, String sender, MailAddressCollection recipients, MailMessage message)
at Aspose.Email.Mail.SmtpClient.Forward(String sender, MailAddressCollection recipients, MailMessage message)

Thanks,
Alex

Hi Alex,


Thank you for sharing the use case. We have added this information to the logged ticket for further consideration by our Product team. If this error occurs all the time you try to send/forward the message, please share your sample message file with us for our further consideration.
Hi,

Code sample:

var m = MailMessage.Load(@"d:\22.eml");
var cl = new SmtpClient("192.168.0.31", 25,"username","password");
cl.Forward("user@domain", "user@domain", m);

Here is a link to sample EML file.

Thanks,
Alex

Hi Alex,


Thank you for sharing the sample file. We have logged this additional information with the logged ticket for consideration by our Product team. and will update you here as there is some information available in this regard.