Memory leak in Aspose.Email version 19.4.0


#1

Hi,
We have memory leak in Aspose.Email current version 19.4.0.
We use Aspose.Email in our application server converting Email to Pdf.
If I load 1000 emails and convert them to pdf, then our server has about 1GB memory that never released. Now I downgrade Aspose.Email to version 6.5.0 then it works fine.
We need a solution urgently.

Thanks
Zhentao


#2

@zhentaosong,

Can you please share source file along with sample code so that we may further investigate to help you out.


#3

Hi, Muhammad,
the following code is called with each mail, after that all objects include MailMessage and MemoryStream are released with Dispose correctly.

Thnaks
Zhentao

private void ImportFromFile(string filename)
{
if (MapiMessage.IsMsgFormat(filename))
{
mOutlookMessage = MapiMessage.FromFile(filename);
mOutlookMessage.Save(MessageStream = new MemoryStream());
}
else
{
mAsposeMessage = MailMessage.Load(filename);
mAsposeMessage.PreferredTextEncoding = Encoding.UTF8;
mAsposeMessage.Save(MessageStream = new MemoryStream(), SaveOptions.DefaultMsg);
mOutlookMessage = MapiMessage.FromStream(MessageStream);
}
}

public override bool TryConvert(IContentStreamEntry streamEntry, FileInfo targetFile, onvertVersionDescriptordescriptor)
{
MailMessage mail = null;
try
{
if (MapiMessage.IsMsgFormat(streamEntry.GetContentStream()))
{
mail = MailMessage.Load(streamEntry.GetContentStream(), new MsgLoadOptions());
}
else
{
mail = MailMessage.Load(streamEntry.GetContentStream(), new EmlLoadOptions());
}
if (mail == null)
{
return false;
}
using (var stream = new MemoryStream())
{
mail.TimeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
var saveOptions = new PdfSaveOptions();
//Save as MHTML
mail.Save(stream, SaveOptions.DefaultMhtml);
//create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = new LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;
//create an instance of Document and load the MTHML from MemoryStream
var mailDocument = new Document(stream, loadOptions);
//save the document to Html file
mailDocument.Save(targetFile.FullName, saveOptions);
}
return true;
}
catch (Exception e)
{
Log.Debug("TryConvert return false: " + e.Message);
return false;
}
finally
{
if (mail != null)
mail.Dispose();
}
}


#4

@zhentaosong,

Can you please share source emails for further investigation along with environment details.


#5

Hi, Muhammad,
in zip file is my source mails. You have to run my code in service application.

Thanks
Zhentao


#6

@zhentaosong,

I am unable to observe any zip file attached. Secondly, please provide a working sample solution reproducing the issue along with snapshot of issue incurring on your end. We may be able to help you further on provision of requested information.


#7

Hello support team,
I sent you a sample program by mail. This way you can reproduce the problem. My question is that the same code works with Aspose.Email version 6.5.0, and it also works when I start the application in UI mode.

Thanks
Zhentao Song


#8

@zhentaosong,

I have not been able to observe any email from your side. Can you please share the sample project here so that we may observe and test that on our end.


#9

How can I share my zip-file. I try to upload. It doesn’t work.
Where can I share a file?


#10

@zhentaosong,

You may share file via Dropbox and inform us here so that we may help you out.


#11

Here is link


#12

@zhentaosong,

I have worked with source file shared by you. An issue with ID EMAILNET-39468 has been created in our issue tracking system to further investigate and resolve the issue. We will share good news with you as soon as the issue will be fixed.


#13

The problem occurs only when I call LoadAsposeLicense() in Service Main, I move LoadAspose License to OnStart, then the error does not occur.


#14

@zhentaosong,

Its good know that issue has been resolved on your own. Can you please confirm if we can close issue now?


#15

I want to know what the difference is when I load license in Main methode and OnStart mehtode. Are there any other effects when I call Load License in OnStart methode?
Why is this problem not present with older Aspose versions?

Best regards
Zhentao


#16

@zhentaosong,

Thank you for providing addition information regarding issue arising on calling LoadAspsoeLicense() in Service Main. I have updated the information in our issue tracking system and will get back to you as soon as the issue will be fixed and request for your patience in this regard.