Skip to content

Potential Memory Leak with Pica Usage in High-Frequency Resizing #247

@Abhinandan777

Description

@Abhinandan777

Hi,

Thank you for creating and maintaining this great library!

I’m using Pica to resize images uploaded by users in my application. Currently, I’m creating a new instance of Pica for every uploaded image, as shown below:

img.onload = async () => {
  let picaInstance = pica();
  try {
    const blob = await picaInstance.resize(img, canvas, { quality: 3 });
    // Additional processing...
  } catch (error) {
    console.error(error);
  }
};

Recently, we noticed a memory spike in our application during high-frequency uploads. I suspect it might be related to creating a new Pica instance for each upload.

My questions are:

  • Could creating multiple Pica instances cause memory issues or inefficiencies in this scenario?

  • Would it be better to move the Pica instance outside the function and reuse it globally?

For context:

  • The application handles multiple concurrent uploads.

  • Performance and memory optimization are priorities.

I’d appreciate any guidance or recommendations for best practices when using Pica in this way.

Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions