We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert Word Documents to PDF in Loop using C# and Manage Optimize High Memory Usage when using Aspose.Words for .NET

Im testing your Aspose.Words for .NET product.

Consider this lines of code:

        public string ToPdf(string filename, string fileAsBase64)
        {
            string filepath = FileRepository.BaseFilepath + filename + ".pdf";
            var bytes = Convert.FromBase64String(fileAsBase64);

            using (var stream = new MemoryStream(bytes))
            {
                try
                {
                    var document = new Document(stream);

                    var saveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Pdf);
                    saveOptions.MemoryOptimization = true;

                    document.Save(filepath, saveOptions);
                }
                catch (Exception e)
                {
                    // logger here
                    throw e;
                }
            }

            return filepath;
        }

My testing app looks like this:

        [Benchmark]
        public List<string> Synchronous()
        {
            var result = new List<string>();
            foreach (var file in data.Files)
            {
                result.Add(ToPdf(file.Filename, file.ContentBase64));
            }

            return result;
        }

in data.Files property exist 10 files with 16 pages.
im storing documents in list of FileDto with property Content - in this property each document exist converted to Base64 as string.

The results presents:

   |        Method |    Mean |    Error |   StdDev |       Gen 0 |      Gen 1 |     Gen 2 | Allocated |
   |-------------- |--------:|---------:|---------:|------------:|-----------:|----------:|----------:|
   |     Synchrous | 3.485 s | 0.1763 s | 0.4945 s | 117000.0000 | 26000.0000 | 6000.0000 | 636.66 MB |

As you can see from 100 runs amount of allocated memory is 640mb avarage. Is it normal memory usage of Aspose.Words for converting documents in loop?

@michasacuer,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document(s) you are getting this problem with
  • Please also create a standalone simple runnable Console Application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your scenario and provide you more information. Thanks for your cooperation.