Skip to content

Memory leak occurs when QR codes used Base64QRCode class #466

@emanuelrm

Description

@emanuelrm

Type of issue

[X] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

To generate QR codes through endpoints, is there any recommended approach or is there a standard way?
var qrGenerator = new QRCodeGenerator();
var input = "00263fd622";
var qrCodeData = qrGenerator.CreateQrCode(input, QRCodeGenerator.ECCLevel.Q);
var qrCode = new Base64QRCode(qrCodeData);
var qrCodeImage = qrCode.GetGraphic(20);

Current Behavior

When there are multiple calls to the endpoint that contains the QR code generation code, the application's memory keeps increasing. While debugging, I was able to verify that this happens when the CreateQrCode method is invoked.

The application starts using 82.7 MB.
Screenshot from 2023-07-14 16-31-40

After 20 requests, the memory increases to 398.9MB.
Screenshot from 2023-07-14 16-32-15

After 100 requests, the memory increases to 1GB.
Screenshot from 2023-07-14 16-33-26

I have already tried calling the dispose methods of the qrGenerator, qrCodeData, and qrCode objects. I have also used the using statements for these objects and directly called GC.Collect(), but none of them were able to deallocate from memory.

Possible Solution (optional)

Steps to Reproduce (for bugs)

QrCoderWebTests.tar.gz
I created (POC) with the mentioned scenario, execute dotnet run, call endpoint http://localhost:5098/
and used a memory monitoring tool to track memory usage.

Your Environment

Version used: 1.4.1
Environment : .net Core 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions