Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak #46

Closed
hipstersmoothie opened this issue Sep 5, 2018 · 7 comments
Closed

Memory Leak #46

hipstersmoothie opened this issue Sep 5, 2018 · 7 comments

Comments

@hipstersmoothie
Copy link

There seems to be a memory leak in jpeg-js. Details here: jimp-dev/jimp#153

@patrickhulce
Copy link
Collaborator

I'm not able to reproduce with the test image provided in that issue on jpeg-js v0.3.4 (or with another large image I had lying around). Using latest JIMP on that image I also don't see any memory leak on my system.

Environment
node v8.11.3
macOS 10.12.6

If you're able to narrow down the repro to a specific environment and test file. I can take a deeper look.

@hipstersmoothie
Copy link
Author

@patrickhulce did you happen to run it in a loop?

@patrickhulce
Copy link
Collaborator

Yep, I did ~20 iterations. Here's my code and output for posterity.

var JIMP = require('jimp')
var fs = require('fs')

// File from #153
var file = fs.readFileSync('file.jpg')

;(async () => {
  var image = null
  for (let i = 0; i < 20; i++) {
    console.time('decode')
    image = await JIMP.read(file)
    console.timeEnd('decode')
    const used = process.memoryUsage().heapUsed / 1024 / 1024
    console.log(`Using approximately ${used} MB`)
  }

  console.log('bitmap length', image.bitmap.data.length)
})()
Output
decode: 221.057ms
Using approximately 17.361053466796875 MB
decode: 172.780ms
Using approximately 8.647064208984375 MB
decode: 140.167ms
Using approximately 8.618217468261719 MB
decode: 134.580ms
Using approximately 8.302398681640625 MB
decode: 131.699ms
Using approximately 8.301979064941406 MB
decode: 132.279ms
Using approximately 8.299003601074219 MB
decode: 143.040ms
Using approximately 8.333412170410156 MB
decode: 131.297ms
Using approximately 8.336555480957031 MB
decode: 131.445ms
Using approximately 8.337242126464844 MB
decode: 127.211ms
Using approximately 8.337486267089844 MB
decode: 135.854ms
Using approximately 8.338554382324219 MB
decode: 134.483ms
Using approximately 8.338180541992188 MB
decode: 133.922ms
Using approximately 8.344223022460938 MB
decode: 128.233ms
Using approximately 8.344345092773438 MB
decode: 126.635ms
Using approximately 8.346481323242188 MB
decode: 137.745ms
Using approximately 8.346206665039062 MB
decode: 130.608ms
Using approximately 8.347244262695312 MB
decode: 133.268ms
Using approximately 8.34716796875 MB
decode: 133.138ms
Using approximately 8.348197937011719 MB
decode: 133.307ms
Using approximately 8.348190307617188 MB
bitmap length 7260000

@patrickhulce
Copy link
Collaborator

@aperkaz from the conversation above, I was not able to observe anything that needs fixing. I'm not aware of any memory leak in jpeg-js, if you have reproducible code and data for this that you can share. Please do.

@SchoppAx
Copy link

SchoppAx commented Apr 20, 2020

Hi @patrickhulce,

the read operation isn't the problem. But if I call an image operation - in my case rotate - i get the following:
grafik

const image = await jimp.read(url);
image.rotate(90);

I don't know if the rotate-operation is part of jpeg-js or another Jimp library (@hipstersmoothie).

I only have 1 GB RAM on backend side and Jimp allocates 800 MB of it, if I call the rotate operation.

@patrickhulce
Copy link
Collaborator

the read operation isn't the problem

Then it's completely unrelated to jpeg-js and it's a JIMP issue. jpeg-js is only for reading and writing JPEGs. This further confirms that the memory issues are not coming from jpeg-js.

@patrickhulce
Copy link
Collaborator

Per #46 (comment) and #46 (comment) there is no observable memory leak from jpeg-js alone. Additionally #54 has introduced fine-grain controls over jpeg-js memory usage, so we'll consider this resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants