OutOfMemoryExption using Aspose.Diagram .NET in large batch operations

Dear Support,

I am evaluating the product Aspose.Diagram with a temporay license.
I am using the .NET-package via the NuGet-package Aspose.Diagram (Version 22.8.0) in VS2022 on Windows 10 x64 (latest version).

One aspect of the evaluation is save a diagram to svg. I have tested this in a loop with 60.000 diagrams and I am quite impressed about the results. No exceptions at all, however I had to use the ‘garbage collector’ freeing resources (otherwise I got OutOfMemoryExceptions throwed from Aspose.Diagram).

I used the following code to prevent the OutOfMemoryExceptions:

            var vsdFiles = System.IO.Directory.EnumerateFiles(sourceDirectory, "*.vsd", System.IO.SearchOption.AllDirectories);
            int count = 0;

            foreach (var vsdFile in vsdFiles)
            {
                string vsdBaseFileName = System.IO.Path.GetFileNameWithoutExtension(vsdFile);

                string svgFileName = $"{vsdBaseFileName}.svg";
                string svgPath = System.IO.Path.Combine(targetDirectory, svgFileName);

                try
                {
                    using (Diagram diagram = new Diagram(vsdFile, LoadFileFormat.Vsd))
                    {
                        diagram.Save(svgPath, SaveFileFormat.Svg);
                    }

                    if (count % 100 == 0)
                    {
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }

                    count++;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(vsdFile + ":" + ex.Message);
                }
            }

Using the Garbage Collector to prevent OutOfMemoryExceptions feels to me as a smell.

Could you investigate this issue, please?

With Kind Regards,

Thierry Knijff
Software Engineer

@tkn1967

We will surely investigate the scenario from this perspective. An investigation ticket as DIAGRAMNET-52950 has been logged in our issue tracking system for the purpose. We will let you know as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

@tkn1967
Please call the dispose method to actively release the memory after each save, but if you process continuous large files, the memory still cannot be released quickly, you still need to release it after collection by gc

                diagram.Save(svgPath, SaveFileFormat.Svg);
                diagram.Dispose(); //add this line

Thanks.

Hi Philipe,

I you for your response.

I am using the following C#-code:

using (Diagram diagram = new Diagram(vsdFile, LoadFileFormat.Vsd))
{
    diagram.Save(svgPath, SaveFileFormat.Svg);
}

The using-statement automatically forces that the Dispose-method is done according the documentation of Microsoft.

Most of the vsd-files (58.664) are smaller than 250 KB of the 60.000 diagrams (only 14 vsd-files are larger than 10.000 KB).

Personally I find it strange that the garbage collector should be called, but this is solving the issue, however it keeps a smell to me.

With Kind Regards,

Thierry

@tkn1967

Thanks for your feedback.

We have recorded it under the ticket and let you know once we have some updates after analyzing the ticket further.