Memory leak in aspose barcode .net in docker

There is a memory leak when reading barcodes in docker with Aspose barcode .net.
the bug is reproducable when running the following code in .net core runtime version 6.x, substitute the image with any valid parcode.

After running a while, the docker container crashes with out of memory exception.
Our initial assesment might be that this relates to the usage of the System.Drawing.Bitmap class in linux, since we have seen other issues with System.Drawing.Bitmap and noticed that Aspose barcode references this class.

-----------CODE TO REPRODUCE------------
using Aspose.BarCode.BarCodeRecognition;

var license = new Aspose.BarCode.License();
license.SetLicense(“Aspose.BarCode.NET.lic”);

while (true)
{
using var bcr = CreateBarCodeReader();
var barCodes = bcr.ReadBarCodes();
Thread.Sleep(10);
}

BarCodeReader CreateBarCodeReader()
{
var barCodeReader = new BarCodeReader(“valid-barcode.png”, new BaseDecodeType[] { DecodeType.SSCC18 }) { QualitySettings = QualitySettings.HighPerformance };
barCodeReader.QualitySettings.AllowIncorrectBarcodes = false;
barCodeReader.QualitySettings.AllowOneDFastBarcodesDetector = true;
return barCodeReader;
}

@mortenhermansentispec,

It looks like you are using Aspose.BarCode on .NET6.0. We already logged a ticket with an id “BARCODENET-37915” in our database to add support for .NET6.0.
Aspose.BarCode will support .NET6, when Aspose.Drawing (our another library) is built to workable state. Because System.Drawing.Common does not support many .NET platforms and we are still in choosing state between Skia.Sharp and Aspose.Drawing for .Net Core. Please note, due to problems with Aspose.Drawing and other factors which could be more serious and the support/solution is shifted at more later time (this year). We will update once any new information is available.

Since we migrated to .NET6 the use of the barcode library causes memory leaks and crashes our pods. Waiting for “Q12023 or earlier” for a version of aspose that works properly on Linux is not an option. Our customers are noticing a steep decline in service response times and are quite vocal about it.

Is there ANY helpful shortterm (!) workaround other than waiting for the next version of the aspose suite?

We currently pay for several aspose.total licences worth a small car each. If that problem is not fixed within the next (very few) weeks we will start migrating to alternative solutions wherever applicable since the issues with aspose on linux have been around since the early netcore days and did not noticeably improve over time.

@sebastian.weber,

We are sorry but there is no better way to cope with it at the moment. Aspose.BarCode does provide .NET6.0 Dll but it will work seamlessly on Windows. Since it depends upon System.Drawing.Common for rendering graphics or drawing objects, so on non Windows os (e.g., linux), it may not work precisely until we implement our own drawing library (e.g., Aspose.Drawing). Anyways, could you please try to add “System.Drawing.EnableUnixSupport” to “*.runtimeconfig.json” as you are using the library on *nix systems.
Ref. document: https://docs.microsoft.com/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

System.Drawing.EnableUnixSupport is only supported for .net 6. In .net 7 this will be removed, and also in .net 6 there is a memory leak when using Aspose.BarCode.
it is easily reproduceable, and not acceptable for a paid product for more than a year to be unusable on linux. If this is to run on docker you need to restart the docker image ocasionally because of this memory leak or you will experience crashes of your application

At this time we are implementing Aspose.Drawing support to Aspose.Barcode project. The implementation is planned to 2023 January or February release.

Main problem here is that System.Drawing and Aspose.Drawing have differences in text drawing, sometimes it is just one pixel difference, sometimes more. We want to reduce differences from .Net Framework and .Net Core barcode generation appearance.

Currently we have something like this:
UPCA_NoWrap.png (4.3 KB)
UPCA_NoWrap_core.png (4.2 KB)

The advantage of this solution that .Net core drawing code (Aspose.Drawing) will written on clear .Net (which could not do Microsoft) without any call to external system libraries, the disadvantage that .Net Core drawing will be slightly different from .Net Framework. And currently Aspose.Drawing does not support Arabic and Hebrew text drawing well.

Do you have a solution implemented for barcode translation, we do not need to generate barcodes, only translate

@mortenhermansentispec,

Could you please elaborate and provide more details on your requirements. We will then understand your needs and assist you accordingly. Do you need to read barcodes?

The aspose bar code .net has barcode reading and barcode creation capabilities. We only need barcode reading capabilities without memory leak. If this has been implemented and released, please let me know. Otherwise, could it be an option to release barcode reading if this works without barcode generation being changed, and then release again when you have the barcode generator implemented with aspose.drawing.

@mortenhermansentispec,

Thanks for providing further details about your requirements.

We now understand your needs. We will update you soon on it.

Any news on this topic?

@mortenhermansentispec,

The feature (Aspose.Drawing support to Aspose.Barcode) is still in progress.

We still need more time on your query:

Please spare us more time. Once we have any new information available on it, we will update you here.

We are sorry for any inconvenience caused!

@mortenhermansentispec,

To update you on it. currently we have problems with fonts fallback on linux but it already works. We will add/include it in current state to February release next month. Also, we have problems with GIF processing in .NET Core, but GIF is obsolete format and modern formats are PNG and TIFF which are supported well. So we are good to go with it.

Could you test Aspose.Drawing.Common on your system.

This library which replaces System.Drawing.Common in February release, but currently it has porblems on some Linux systems.

Could you test text drawing fuctions - draw some text on bitmap. It has simular to System.Drawing functions but namespaces Aspose.Drawing.*?

What should I test? We use aspose barcode, but does not use the drawing component. we only use it for reading barcodes, and not generating barcodes.

We see memory leak when reading/decoding the barcodes in linux.

@mortenhermansentispec,

Just to make sure that Aspose.Drawing.Common would work in your environment, we requested you to kindly test text drawing functions - draw some text on bitmap. It is similar to System.Drawing functions but namespace is as Aspose.Drawing. This way you would at least know Aspose.Drawing.Common would work fine in advance. Aspose.Drawing.Common would be included into February release.

I am also having this memory leak problem in linux systems due to System.Drawing.

I have seen in the release notes of 23.2 version that you have finally switched to the Aspose.Drawing implementation. I am looking forward to try if this new version solves all the System.Drawing related problems but I can’t see the new version released in NuGet. Any ETA for this? Is there any other way to get this new version?

1 Like

@alberto2436,

Yes, Aspose.BarCode for .NET 23.2 was not released to nuget repos. yet. We will surely do it after performing certain configurations. We will check if we could provide latest updates on it.

In the meantime, you may download the Dlls version and manually add reference to your desired Aspose.BarCode for .NET assembly in your project.

We are sorry for any inconvenience caused!

I am trying to use the 23.2 Aspose.Barcode DLL as you suggested but I am facing an issue.

Barcode reader needs Aspose.Drawing.Bitmap but It doesn’t exist in the Aspose.Drawing assembly. I have tried 23.1 and 23.2 versions of Aspose.Drawing. Which is the correct one that works with Aspose.Barcode 23.2?

@alberto2436,

We have:

  • Aspose.Drawing.Bitmap from Aspose.Drawing.Common
  • System.Drawing.Bitmap from Aspose.Drawing.

Currently older Aspose.Drawing uses System.Drawing namespace and conflicts with System.Drawing.Common (or any libraries which use it).

You need to use latest Aspose.Drawing.Common.

<ItemGroup>
	<PackageReference Include="Aspose.Drawing.Common" Version="23.2.0" />
	<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup>

Hope, this helps a bit.