FastReport icon indicating copy to clipboard operation
FastReport copied to clipboard

Memory not freed

Open Ramoshuai opened this issue 4 years ago • 22 comments

I put an Image on FRX, Request ‘TestReport’ multiple times,My container footprint is 1GB or higher. Is there a problem with my code?

[Route("/TestReport")]
        public string TestPrint(string type)
        {

            using Report report = new Report();
            report.Load("3.frx");

            using FileStream fs = new FileStream("1.png", FileMode.Open, FileAccess.Read);
            byte[] buffur = new byte[fs.Length];
            fs.Read(buffur, 0, (int)fs.Length);
            fs.Close();

            using ImageExport image = new ImageExport();
            image.ImageFormat = ImageExportFormat.Jpeg;
            image.Resolution = 300;

            var data = new List<object>() { new { Image = buffur } };
            report.RegisterData(data, "Test");
            report.Prepare();
            using MemoryStream reportImageStream = new MemoryStream();
            report.Export(image, reportImageStream);

            return Convert.ToBase64String(reportImageStream.ToArray());
        }

My Code

Ramoshuai avatar Jul 22 '21 01:07 Ramoshuai

There also seems to be a container exit issue under concurrent requests.

Ramoshuai avatar Jul 22 '21 02:07 Ramoshuai

Hi,

Tell more about your testing environment (Linux, Windows). Could you show your Dockerfile?

fediachov avatar Jul 22 '21 07:07 fediachov

@fediachov I pushed the image I was using to DockerHub https://hub.docker.com/r/qq709821512/hq

Ramoshuai avatar Jul 22 '21 08:07 Ramoshuai

Hi, What version of FastReport OpenSource do you use? I can't reproduce memory leak and problem with concurrent requests in container in version 2021.3.17.

0legK avatar Jul 28 '21 10:07 0legK

@0legK Is there something wrong with my container?

Ramoshuai avatar Jul 28 '21 10:07 Ramoshuai

My container state image

Ramoshuai avatar Jul 28 '21 11:07 Ramoshuai

Is there something wrong with my container?

I don't think so. I have tested you application https://github.com/BlackPig-dev/TestFastReport I just updated the versions: FastReport.OpenSource to 2021.3.17 and FastReport.Compat to 2021.2.10

0legK avatar Jul 28 '21 11:07 0legK

My code uses the version of 2021.3.17

  <ItemGroup>
    <PackageReference Include="FastReport.OpenSource" Version="2021.3.17" />
  </ItemGroup>

Ramoshuai avatar Jul 28 '21 11:07 Ramoshuai

Is there something wrong with my image? Something to do with libgdiplus?

Ramoshuai avatar Jul 28 '21 11:07 Ramoshuai

I need time to check it again. I'll let you know later.

0legK avatar Jul 28 '21 11:07 0legK

@0legK Thanks a lot

Ramoshuai avatar Jul 28 '21 12:07 Ramoshuai

Hi,

I have tested it again. I have not find any memory leaks in Image export of FastReport OpenSource. And I have not find memory leaks when report preparing. Also I don't see any problems in your test applicaton.

About memory consumption. It grows every time when page refreshes. Sometimes memory consumption grows down. When page closes, all memory going freed up.

It looks like usual work of GC. GC runs from time to time when system is not loaded. And when there is a lack of memory.

0legK avatar Jul 29 '21 13:07 0legK

@0legK I just manually refreshed the page frequently with F5, and the memory was already high without even using the stress test tool

https://user-images.githubusercontent.com/28700143/127590246-03d87da2-db77-48c1-bb46-e2b630eba418.mp4

Ramoshuai avatar Jul 30 '21 02:07 Ramoshuai

@0legK @fediachov I wonder if you have started to deal with this problem.

Ramoshuai avatar Aug 06 '21 06:08 Ramoshuai

The problem could be with libgdiplus. It does not reproduce on all systems and versions of this library. For example. Could you test this solution?

fediachov avatar Nov 19 '21 08:11 fediachov

@Ramoshuai I tried the solution and it works fine the container memory went down to ~200MB

This is my current Dockerfile, may be it can be better but this is what worked with me.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
RUN apt-get update && apt-get install -y --allow-unauthenticated libc6-dev libgdiplus libx11-dev
RUN apt-get install -y libgif-dev autoconf libtool automake build-essential gettext libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev libpango1.0-dev git
WORKDIR /var/customLib
RUN git clone https://github.com/mono/libgdiplus.git
WORKDIR /var/customLib/libgdiplus
RUN ./autogen.sh --with-pango --prefix=/usr
RUN make
RUN make install
WORKDIR /app
EXPOSE 80

ElBedeawi avatar Nov 19 '21 12:11 ElBedeawi

@ElBedeawi @fediachov I tried to recompile the environment again, but still the same I uploaded my code here my code Under concurrent requests, the memory still quickly rose to 1G

Ramoshuai avatar Nov 25 '21 09:11 Ramoshuai

Hi,

We have fixed some memory leaks. Please, try latest version 2021.4.16. I hope it can be better.

0legK avatar Nov 25 '21 10:11 0legK

Hi,

We have fixed some memory leaks. Please, try latest version 2021.4.16. I hope it can be better.

The version I use is the latest 2021.4.16 <PackageReference Include="FastReport.OpenSource" Version="2021.4.16" />

Ramoshuai avatar Nov 26 '21 01:11 Ramoshuai

Hi, we are experienceing the same behaviour with version 2022.2.12. This only happends in linux env, not in windows.

Can anyone confirm if @ElBedeawi solution works? Is it a problem with libgdiplus?

Regards

matiaskusack avatar Jul 05 '22 06:07 matiaskusack

Hi, we are experienceing the same behaviour with version 2022.2.12. This only happends in linux env, not in windows.

Can anyone confirm if @ElBedeawi solution works? Is it a problem with libgdiplus?

Regards

I haven't tried the latest version yet, but for the version I'm using "2021.4.13" it was the issue and building it using that dockerfile worked fine for me.

ElBedeawi avatar Jul 05 '22 07:07 ElBedeawi

Ok, I can confirm that in our case, what @ElBedeawi said solved the memory problem.

Thank you very mutch!

matiaskusack avatar Jul 05 '22 14:07 matiaskusack