Free Support Forum - aspose.com

Memory leak when invoking Print on MailPrinter (PrintFormat.Tiff)

There appears to be a memory leak when invoking MailPrinter.Print.
This eventually leads to an out of memory exception being thrown.
I have attached a sample project which includes a unit test project (SampleLibTests) which can be run.
To get this to run you will need to add your license to the SampleLib Project.

In SampleTests.cs there is a property which controls the amount of iterations that are run.
There are 3 tests:

ConvertUsingFileSystem - Invokes Print on MailPrinter saving to a file. Creates and disposes the MailMessage object. There is a subtle leak which grows over time and memory pressure grows linearly. On my machine this appears to grow to around 300MB after 1000 iterations.

ConvertUsingStream - Invokes Print on MailPrinter saving to a stream. Creates and disposes the MailMessage object and a memory stream. There is a subtle leak which grows over time and memory pressure grows linearly. On my machine this appears to grow to around 300MB after 1000 iterations.

Invoke - Creates and disposes the MailMessage object. This does not leak and memory pressures appears to be constant. On my machine this appears to stay around 40MB after 1000 iterations.

SampleApp.zip (24.0 KB)

@Francis73

Can you please confirm which product version you have used. If you are using any older version, please use Aspose.Email for .NET 20.8 on your end and share feedback. Please also provide the snapshot of memory profiling where you suspect a memory leak.

I had originally used 20.5.0 and I have since upgraded to 20.8.0. However, it is still exhibiting this issue.
Please find attached the snapshot.
image.png (428.8 KB)

Updated Sample
SampleApp.zip (24.0 KB)

        using (var stream = new MemoryStream())
        {
            using (var mailMessage = MailMessage.Load(InputPath))
            {
                var printer = new MailPrinter();
                printer.Print(mailMessage, stream, PrintFormat.Tiff); // This is the offending line of code
            }
        }

@Francis73

After observing the image shared by you, I have opened a ticket with ID EMAILNET-39915 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.

The issues you have found earlier (filed as EMAILNET-39915) have been fixed in this update.