In below code I am adding 30 MB image in 4 slides each.
Initial memory(Working Set) for this application is 30 MB.
After running below code and even after calling GC.Collect(), this process holds 170 - 200 MB memory. So my question is why the complete memory not being released?
Here is the link for image file: https://file.io/PqBbW7AnEuW1
This issue is reproducible with any type of image.
Aspose Slides Version - 21.1.0
.NET Version - 3.1.405
OS - Ubuntu 18.04
using System;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
using System.Runtime;
using System.Threading;
namespace dotnet
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Process Id: " + Process.GetCurrentProcess().Id);
logMemory();
Console.WriteLine("Generating PPT....");
AddImageToPPT();
Console.WriteLine("Finished Generating PPT");
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
logMemory();
}
static void logMemory()
{
var workingSet = 0.0;
Process proc = Process.GetCurrentProcess();
workingSet = proc.WorkingSet64 / (1024 * 1024);
proc.Dispose();
Console.WriteLine("Working Set in MBs: " + workingSet);
}
static void AddImageToPPT()
{
using (Presentation pres = new Presentation())
{
for (var i = 1; i < 5; i++)
{
Console.WriteLine("Addding Slide No: " + i);
FileStream fileStream = new FileStream("./img.png", FileMode.Open);
IPPImage img = pres.Images.AddImage(fileStream, LoadingStreamBehavior.KeepLocked);
pres.Slides.AddClone(pres.Slides[0]);
pres.Slides[i].Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, 700, 500, img);
pres.Save("PPT-01.pptx", SaveFormat.Pptx);
logMemory();
}
logMemory();
}
}
}
}