Skip to content

Memory Leak in Image #1139

Closed
Closed
@hhelwich

Description

@hhelwich

There is a memory leak in the current stable version of node-canvas.

Steps to Reproduce

  1. Start some program to observe system memory
  2. Run the following code in node (set url to some Jpg file):
const canvas = require('canvas');

const loadImageNTimes = n => {
    if (n > 0) {
        const image = new canvas.Image();
        image.onload = () => {
            // Uncomment the following line to free image memory:
            // image.src = '';
            loadImageNTimes(n - 1);
        };
        image.src = 'some.jpg'; // Set Url to an existing Jpg file
    }
};
loadImageNTimes(500);
  1. You should see that the memory is now growing linearly
  2. Uncomment the line image.src = '' and run the script again
  3. The memory stays constant now

Environment:

  • node-canvas 1.6.10
  • node 9.11.1 on Ubuntu 17.10

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