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

Free Support Forum - aspose.com

PDF to JPEG memory leak in Unix environment

Our team has done comparisons in a Windows based environment vs a Unix environment.

Several dozen requests cause the service to run out of memory in the Unix environment, but this does not occur in the Windows based environment.

Code snippet:

  public async Task<IActionResult> MemLeakSample(IFormFile formFile)
     using MemoryStream sourceDocument = new MemoryStream();
     await formFile.CopyToAsync(sourceDocument);
     List<string> images = new List<string>();
     using Document pdfDoc = new Document(sourceDocument);
     int docPageCount = pdfDoc.Pages.Count;

     for (int pageCount = 1; pageCount <= docPageCount; pageCount++)
        using (MemoryStream memStream = new MemoryStream())
           using Page page = pdfDoc.Pages[pageCount];
           Rectangle pageRect = page.GetPageRect(true); // Get page size respecting page orientation
           JpegDevice jpegDevice = new JpegDevice(Convert.ToInt16(pageRect.Width), Convert.ToInt16(pageRect.Height), new Resolution(72), 25);

           // Convert a particular page and save the image to stream
           jpegDevice.Process(page, memStream);

           // Convert to byte array, and then to base 64 image url
           images.Add("data:image/jpeg;base64," + Convert.ToBase64String(memStream.ToArray()));

     return this.Ok(images);


FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
COPY DocumentService ./
RUN dotnet restore 
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
COPY --from=build-env /app/out .

EXPOSE 5000/tcp

RUN apt-get update && apt -y install libgdiplus && ln -s libgdiplus.so gdiplus.dll && apt-get install -y libc6-dev && apt -y install apache2 && apt-get install -y supervisor && a2enmod headers && a2enmod proxy && a2enmod proxy_http && a2enmod deflate

ADD DocumentService/docker/service.conf /etc/apache2/sites-available/
ADD DocumentService/docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

RUN rm /etc/apache2/sites-available/000-default.conf && cp /etc/apache2/sites-available/service.conf /etc/apache2/sites-available/000-default.conf

ENTRYPOINT ["/usr/bin/supervisord"]


Could you please ZIP and attach your input PDF and Visual Studio application to reproduce the same issue at our end? We will investigate the issue and provide you more information on it.

@tahir.manzoor Sample is attached to this reply. Thank you for your assistance.

PDF_Sample.zip (1.2 MB)


We have logged this problem in our issue tracking system as PDFNET-51471. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.