Using Aspose.Slides on Linux Container with .NET Core Does Not Release Memory

@andrey.potapov Also with this PPT, the issue is still replicable. Memory is not released.Sample.zip (1.6 MB)

@ansamohdsh,
Thank you for the sample presentation. We will also investigate the case.

Any Update on our request @andrey.potapov

@ansamohdsh,
As far as I can see, our developers continue to work on this issue this week. Unfortunately, I don’t have any additional information yet.

hello @andrey.potapov,

As we are approaching weekend, wanted to check with you if you have any updates for us ?

@ansamohdsh,
I requested news on the issue from our development team and will let you know as soon as possible.

@ansamohdsh,
We are currently working on identifying the cause of the error that occurs during the build process of your Dockerfile. We are attempting to reproduce the issue locally.

Could you please provide the Dockerfile or the relevant part of the Dockerfile where the provided script for updating the libgdiplus library is used? The memory leak issue can be resolved by installing the latest version of the libgdiplus library (6.0.5-0xamarin1+ubuntu2004b1), which comes with Mono:
https://www.mono-project.com/download/stable/#download-lin

@andrey.potapov We are using the snippet that you shared with us in the last update as below:

FROM mcr.microsoft.com/dotnet/aspnet:7.0-focal

#FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal

#FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine

# RUN echo -e "https://dl-cdn.alpinelinux.org/alpine/edge/testing/\n" >> /etc/apk/repositories && \

#     apk update && \

#     apk --no-cache add msttcorefonts-installer fontconfig libgdiplus icu-libs curl && \

#     update-ms-fonts && \

#     fc-cache -f 

# RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections

# RUN apt-get update -q && \

#   DEBIAN_FRONTEND=noninteractive apt-get install ttf-mscorefonts-installer fontconfig libgdiplus curl -y -q && \

#   fc-cache -vr

RUN apt-get update -q && \

apt-get install -y -q gnupg ca-certificates && \

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \

echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \

apt-get update -q && \

DEBIAN_FRONTEND=noninteractive apt-get install -y -q ttf-mscorefonts-installer fontconfig libgdiplus curl && \

fc-cache -vr


WORKDIR /app

COPY bin/Release/net7.0/publish/ /app/

RUN mkdir obj logs && chown nobody obj logs && apt-get remove -q -y curl

# RUN mkdir obj logs && chown nobody obj logs && apk del curl

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# USER nobody

ENTRYPOINT ["dotnet", "SomeDLL.dll"]

@ansamohdsh,
Thank you for the additional information. I forwarded it to our developers.

@ansamohdsh,
Our developers have investigated your log and Dockerfile. Based on the provided log, the ttf-mscorefonts-installer package is unavailable. It’s important to note that for Aspose.Slides under aspnet:6.0-7.0, there’s no need to install the libgdiplus library in the Linux environment. This is because, starting from .NET 6.0, Aspose.Slides no longer relies on the libgdiplus library. Microsoft has discontinued support for System.Drawing.Common in the Linux environment beginning with .NET 6.0. Therefore, installing the latest version of the libgdiplus library is unnecessary under .NET 6.0 and .NET 7.0. The previously provided Dockerfile script was developed for .NET 5.0 to update the libgdiplus library, aiming to fix the memory leak issue.

Here is the Dockerfile for .NET 6.0 and .NET 7.0 with some comments:

#FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
#FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
#FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
#FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base

#Uncomment to install the ttf-mscorefonts-installer for aspnet:6.0 (runtime:6.0) and aspnet:7.0 (runtime 7.0). Please comment it out for aspnet:x.x-focal, as it doesn't work.
 RUN echo "deb http://deb.debian.org/debian/ buster main contrib non-free" > /etc/apt/sources.list && \
    echo "deb-src http://deb.debian.org/debian/ buster main contrib non-free" >> /etc/apt/sources.list 


#The libgdiplus package can be removed if you'd like
RUN apt-get update -q && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y -q ttf-mscorefonts-installer fontconfig libgdiplus curl && \
    fc-cache -vr

#Install the necessary libraries for Aspose.Slides under .NET 6.0 and .NET 7.0, as they may be missing in the Docker image
RUN apt-get update && apt-get install -y \
 libfontconfig1 \
 libfreetype6 \
 libexpat1 \
 libpng16-16


WORKDIR /app

#FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build

WORKDIR /src
COPY ["SomeDLL/SomeDLL.csproj", "SomeDLL/"]
RUN dotnet restore "SomeDLL/SomeDLL.csproj"
COPY . .
WORKDIR "/src/SomeDLL"
RUN dotnet build "SomeDLL.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "SomeDLL.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SomeDLL.dll"]

Please note that for .NET 6.0 and .NET 7.0 were added the following commands to the Dockerfile:

RUN apt-get update && apt-get install -y \
 libfontconfig1 \
 libfreetype6 \
 libexpat1 \
 libpng16-16

These commands install the necessary libraries for Aspose.Slides in the Linux environment under .NET 6.0 and .NET 7.0, which may be missing in the docker image.

Updated Dockerfile for .NET 5.0, just in case:

FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
#FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
#FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base

# Uncomment to install the ttf-mscorefonts-installer for aspnet:5.0 and runtime:5.0. Please comment it out for aspnet:5.0-focal, as it doesn't 
#RUN echo "deb http://deb.debian.org/debian/ buster main contrib non-free" > /etc/apt/sources.list && \
    #echo "deb-src http://deb.debian.org/debian/ buster main contrib non-free" >> /etc/apt/sources.list

# Update package lists,  install the necessary packages and Update font caches
RUN apt-get update -q
ENV DEBIAN_FRONTEND=noninteractive
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN apt-get install -y -q ttf-mscorefonts-installer fontconfig curl
RUN fc-cache -vr

# Install the latest version of libgdiplus library for aspnet:5.0, runtime:5.0 and aspnet:5.0-focal to resolve memory leak
RUN apt-get update -q && \
    apt-get install -y -q gnupg ca-certificates && \
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \

    #Uncomment this code for aspnet:5.0 and runtime:5.0. Comment it out for aspnet:5.0-focal because it doesn't work
    #echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \
    #Uncomment this code for aspnet:5.0-focal. However, you should comment it out for aspnet:5.0 and runtime:5.0, as it doesn't work.
    echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \

    apt-get update -q && \
    apt-get install -y -q libgdiplus

WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["SomeDLL/SomeDLL.csproj", "SomeDLL/"]
RUN dotnet restore "SomeDLL/SomeDLL.csproj"
COPY . .
WORKDIR "/src/SomeDLL"
RUN dotnet build "SomeDLL.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "SomeDLL.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SomeDLL.dll"]

Thank you so much @andrey.potapov for sharing the docker updates.

Did your team also got a chance to review the sample ppt for which high memory issue still exists?

@ansamohdsh,
I forwarded your question to our developers and will get back to you as soon as possible.

@ansamohdsh,
As for the Sample.pptx file, the memory leak issue has also been fixed. It was tested with 500 iterations of loading and saving the presentation. The average memory consumption during testing ranged from 1 gigabyte to 1.35 gigabytes.

Hi @andrey.potapov,
Thank you for the updates.
I have a few more questions:

  • Is the memory leak issue fixed with the docker file changes you shared recently ?

  • Is it available for .net core 5 or .net core 7?

  • Do we need to upgrade to any specific Aspose Library version ?

@ansamohdsh,
The memory leak issue occurs under .NET 5.0 in the Linux environment. Under .NET 5.0, Aspose.Slides uses the System.Drawing.Common library, which in turn relies on the libgdiplus library. The libgdiplus library is part of Mono: libgdiplus | Mono. Investigations carried out for this task have revealed that the memory leak occurs in unmanaged memory in the libgdiplus library (version 6.0.4+dfsg-2). However, in version 6.0.5-0xamarin1+ubuntu2004b1, which is currently installed with Mono, the memory leak issue is not observed.

This problem can be reproduced outside of Aspose.Slides under .NET 5.0 by solely using System.Drawing.Common. Here is an example of code that reproduces the memory leak for .NET 5.0 in a Linux environment (the libgdiplus library is installed by default with the libgdiplus package):

for (int i = 0; i < 50; i++)
{
    using (Bitmap bmp = new Bitmap(8 * 1024, 8 * 1024))
    using (Graphics graphics = Graphics.FromImage(bmp))
    {
        graphics.Clear(Color.White);
    }
}; //-memory allocated for Bitmap is freed, but the memory for the Graphics object is not freed, graphics.Dispose() doesn't work. 

In the Dockerfile we provided for .NET 5.0, there have been added some commands to install the latest version of the libgdiplus library (6.0.5-0xamarin1+ubuntu2004b1) from the Mono repository:

# Install the latest version of libgdiplus library for aspnet:5.0, runtime:5.0 and aspnet:5.0-focal to resolve memory leak
    RUN apt-get update -q && \
    apt-get install -y -q gnupg ca-certificates && \
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \

    #Uncomment this code for aspnet:5.0 and runtime:5.0. Comment it out for aspnet:5.0-focal because it doesn't work
    #echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \
    #Uncomment this code for aspnet:5.0-focal. However, you should comment it out for aspnet:5.0 and runtime:5.0, as it doesn't work.
    echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \

    apt-get update -q && \
    apt-get install -y -q libgdiplus

In .NET 6.0/7.0, the memory leak issue does not occur because of Aspose.Slides no longer uses System.Drawing.Common + libgdiplus in the Linux environment. Aspose.Slides uses its own implementation of System.Drawing. Microsoft has discontinued support for System.Drawing.Common on the Linux platform starting from .NET 6.0, and it is now only supported on the Windows platform. More details can be found here: Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn.

Yes, it’s fixed for .NET 5.0. There have been added some commands to the Dockerfile to install the latest version of libgdiplus to fix the memory leak. For .NET 6.0/7.0 this issue is not reproduced. For .NET 6.0/7.0 in the Dockerfile, there have been added commands to install necessary libraries used by Aspose.Slides, which may be missing in the Docker image:

#Install the necessary libraries for Aspose.Slides under .NET 6.0 and .NET 7.0, as they may be missing in the Docker image
RUN apt-get update && apt-get install -y \
 libfontconfig1 \
 libfreetype6 \
 libexpat1 \
 libpng16-16

The memory leak issue is available for .NET Core 5 in the Linux environment, but it is not available for .NET Core 7.

No, there is no need for that as the memory leak issue is not related to Aspose.Slides.

Note: there are some comments in the Dockerfiles for clarification.

Hello @andrey.potapov
we updated our docker files but fortunately we are still encountering the memory spikes.
Refer to the screenshots.23661ce6-e96e-47c0-94f1-aa79688346d3.gif (450.7 KB)
f0cfcd6d-cf3e-4db5-b514-b3f3bd36c3cc.gif (515.4 KB)

@ansamohdsh,
Please share your updated docker files. Then we will continue investigating the case.

.net 5.0 Docker File

FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base

#FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base

#FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base

# Uncomment to install the ttf-mscorefonts-installer for aspnet:5.0 and runtime:5.0. Please comment it out for aspnet:5.0-focal, as it doesn't 

#RUN echo "deb http://deb.debian.org/debian/ buster main contrib non-free" > /etc/apt/sources.list && \

    #echo "deb-src http://deb.debian.org/debian/ buster main contrib non-free" >> /etc/apt/sources.list

# Update package lists,  install the necessary packages and Update font caches

RUN apt-get update -q

ENV DEBIAN_FRONTEND=noninteractive

RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections

RUN apt-get install -y -q ttf-mscorefonts-installer fontconfig curl

RUN fc-cache -vr

# Install the latest version of libgdiplus library for aspnet:5.0, runtime:5.0 and aspnet:5.0-focal to resolve memory leak

RUN apt-get update -q && \

    apt-get install -y -q gnupg ca-certificates && \

    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \

    #Uncomment this code for aspnet:5.0 and runtime:5.0. Comment it out for aspnet:5.0-focal because it doesn't work

    #echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \

    #Uncomment this code for aspnet:5.0-focal. However, you should comment it out for aspnet:5.0 and runtime:5.0, as it doesn't work.

    echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \

    apt-get update -q && \

    apt-get install -y -q libgdiplus

    



WORKDIR /app

COPY bin/Release/net5.0/publish/ /app/

RUN mkdir obj logs && chown nobody obj logs && apt-get remove -q -y curl

# RUN mkdir obj logs && chown nobody obj logs && apk del curl

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# USER nobody

ENTRYPOINT ["dotnet", "Sample.dll"]

for .net 7 @andrey.potapov

#FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base

#FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base

#FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base

#FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base

#Uncomment to install the ttf-mscorefonts-installer for aspnet:6.0 (runtime:6.0) and aspnet:7.0 (runtime 7.0). Please comment it out for aspnet:x.x-focal, as it doesn't work.

 RUN echo "deb http://deb.debian.org/debian/ buster main contrib non-free" > /etc/apt/sources.list && \

    echo "deb-src http://deb.debian.org/debian/ buster main contrib non-free" >> /etc/apt/sources.list 

#The libgdiplus package can be removed if you'd like

RUN apt-get update -q && \

    DEBIAN_FRONTEND=noninteractive apt-get install -y -q ttf-mscorefonts-installer fontconfig libgdiplus curl && \

    fc-cache -vr

#Install the necessary libraries for Aspose.Slides under .NET 6.0 and .NET 7.0, as they may be missing in the Docker image

RUN apt-get update && apt-get install -y \

 libfontconfig1 \

 libfreetype6 \

 libexpat1 \

 libpng16-16



WORKDIR /app

COPY bin/Release/net7.0/publish/ /app/

RUN mkdir obj logs && chown nobody obj logs && apt-get remove -q -y curl

# RUN mkdir obj logs && chown nobody obj logs && apk del curl

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# USER nobody

ENTRYPOINT ["dotnet", "Sample.dll"]

@ansamohdsh,
Thank you for the additional information. I’ve forwarded it to our developers. We will continue investigating the case.