Huge memory consumption while generating power point presentation

Hi, I am using aspose for .net library in my project for generating power point presentations. We have requirement to generate slides more than 300. While doing this aspose library is consuming lot of memory. Is there a way to restrict the memory usage? Please let me know any solution.

@cartositt,
Let me clarify, please:

  1. What kind of content are you using to generate the presentations?
  2. What are your memory limits?
  3. Which version of the Aspose.Slides library are you using?

Hi Andrey,

Thank you for your quick response. Below are the answers
1.What kind of content are you using to generate the presentations?
-> Majority of the slides are containing image content. Image size could vary upto 10MB.

What are your memory limits?
-> Our memory limit is 1GB( We are okay if limiting memory slow down the performance)

Which version of the Aspose.Slides library are you using?
-> Aspose.Slides for .NET 20.3.0 (We are using this in dotnet core 3.1)

@cartositt,
Reducing memory consumption can be achieved by using disk space. A presentation content has to be stored on the disk to keep your memory consumption low. I would suggest you to try two ways and choose the best for your tasks.

The first way
You can add images to presentations as BLOBs:

// presentation is IPresentation object, imageFileStream is Stream object
IPPImage image = presentation.Images.AddImage(imageStream, LoadingStreamBehavior.KeepLocked);
presentation.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 20, 20, 300, 200, image);

Please look at Manage Blob section in Aspose.Slides documentation for more details.

The second way
You can create an empty presentation and save it to a file. Then you should open the file as the large presentation as follows:

var loadOptions = new LoadOptions
{
    BlobManagementOptions =
    {
        PresentationLockingBehavior = PresentationLockingBehavior.KeepLocked,
    }
};

using (var presentation = new Presentation(largePresentationFilePath, loadOptions))
{
    // add content here
}

For more details: Open Large Presentation.

Also, you can restrict memory consumption indicating additional options as below:

loadOptions.BlobManagementOptions.MaxBlobsBytesInMemory = 1024 * 1024 & 1024; // 1 GB
loadOptions.BlobManagementOptions.IsTemporaryFilesAllowed = true;

Additional API Reference: BlobManagementOptions

Thank you so much Andrey, Let me try these options.