Memory leaks.
overflowz opened this issue · comments
I was testing it on nodejs (node-resemble-v2) and I got a lot of leaks when doing:
let deferred = () => {
return new bluebird((resolve, reject) => {
resemble(masterImages[i]).compareTo(childImages[j]).onComplete(resolve);
});
}
let result: any = await deferred();
After this, memory get's leaked (more I call, more leaks I get).
Any thoughts?
Shouldn't this be mentioned on node-resemble-v2
instead of here?
This is the original core and had some memory optimization in one of the last releases
It might be, but node-resemble-v2 is using this as core library and leaks are coming from here.
This is the heapsnapshot files (before entering in loop and after loop, see code below:
var heapdump = require('heapdump');
var resemble = require('node-resemble-v2');
heapdump.writeSnapshot('beforeloop.heapsnapshot');
for (var i = 0; i < 50; i++) {
resemble('./1.png').compareTo('./2.png').onComplete(function resembleComplete(result) {
console.info('completed');
if(i === 50 - 1) {
heapdump.writeSnapshot('afterloop.heapsnapshot');
}
});
}
edit: seems onComplete function is leaking. Without onComplete, memory is fine.
onComplete
kicks of the analysis, if anything is going to leak it'll be that. Not something I'm going to be able to look into soon, but will be happy to review a Pull Request
I was thinking, maybe it's canvas library leak itself rather than resemble?
Hi @overflowz and @jamescryer ,
The remark of @overflowz made me thinking, I also use ResembleJS, as a node version, in my image-comparison module. This one is based on the latest version of ResembleJS and based on node-resemblejs and can be found here.
@overflowz , can you verify if it's in there? IF not, then it can be a canvas issue.
has this been solved? Using nodejs I also see the process not garbage collecting memory
Sorry for late reply,
I'm not sure if it's fixed or not. Sadly I don't have much time anymore to analyse it, sorry!
As a workaround, I used pngjs/pixelmatch library directly.
Here's the snippet I used for comparison. It also used to compare images way much faster (8-10x) than Resemble's compareTo
method (no offense!).
export async function compareImages(image1: string, image2: string): Promise<number> {
return new bluebird((resolve, reject) => {
let img1, img2;
img1 = fs.createReadStream(image1).pipe(new pngjs.PNG()).on('parsed', () => {
img2 = fs.createReadStream(image2).pipe(new pngjs.PNG()).on('parsed', () => {
let diff = pixelmatch(img1.data, img2.data, null, img1.width, img1.height);
let percent = (Math.round(100 * 100 * diff / (img1.width * img1.height)) / 100);
img1 = img2 = diff = null;
return resolve(percent);
});
});
}) as bluebird<number>;
};
This is the only feature I wanted from this library though.
Kind regards.
It's 2018, any updates on the issue? I need to compare some SVGs and font glyphs.
Behaves much better now, in v2.10.0