Skip to content

Utility method loadImage memory leak #1705

@and2

Description

@and2

Issue

Calling the utility method loadImage (or just using the Image object for the matter) does not release the memory used.
The same happens with both local and remote images. Loading a 3MB remote jpg in the below example would keep the rss memory at ~400MB and would not be GCed.

Awaiting for the promise to resolve, setting the returned image to null / the source to null makes no difference to the memory level.

Steps to Reproduce

const { loadImage } = require('canvas')

for (let i=1; i<=10; i++) {
  loadImage('path_to_image').then(function(){
    console.log('loaded')
  })
}

setInterval(()=>{
  if (global.gc) { global.gc() }
  console.log('rss: ' + process.memoryUsage().rss / (1024 * 1024) + 'MB')
}, 1000)

Your Environment

  • Version of node-canvas: 2.6.1 built from source
  • Environment: node 12.19.1 & node 14.15.1 on MacOS 10.13.6 & Heroku 18 stack (Ubuntu 18.04)

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