You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Memory leaks appear in asynchronous version of Canvas.toBuffer method and Canvas.createPNGStream method
Canvas.toBuffer causes large memory leak
Canvas.createPNGStream causes small memory leak
Steps to Reproduce
constfs=require('fs');const{ createCanvas, Image }=require('canvas');constimage=newImage();image.src=fs.readFileSync('some_test_image.png');constcanvas=createCanvas(image.width,image.height);canvas.getContext('2d').drawImage(image,0,0);functionsaveUsingToBuffer(path,canvas){returnnewPromise((resolve,reject)=>{canvas.toBuffer((err,buffer)=>{if(err){reject(err);}else{fs.writeFile(path,buffer,err=>{if(err){reject(err);}else{resolve();}});}});});}functionsaveUsingSyncToBuffer(path,canvas){returnnewPromise((resolve,reject)=>{constbuffer=canvas.toBuffer();fs.writeFile(path,buffer,err=>{if(err){reject(err);}else{resolve();}});});}functionsaveUsingStream(path,canvas){returnnewPromise((resolve,reject)=>{constout=fs.createWriteStream(path);conststream=canvas.createPNGStream();stream.pipe(out);out.on('finish',resolve);out.on('error',reject);});}asyncfunctiontest(){while(true){// uncomment one test to run// await saveUsingSyncToBuffer('test.png', canvas); // synchronous toBuffer() (no leak)awaitsaveUsingToBuffer('test.png',canvas);// asynchronous toBuffer() (large leak)// await saveUsingStream('test.png', canvas); // createPNGStream() (small leak)gc();}}test();
You need to provide some test png image to load some_test_image.png
The script will keep saving test.png image in current path
Run with --expose-gc flag (or comment out call to gc()
Your Environment
Version of node-canvas: 2.0.1
Environment: node 9.11.2 on Windows 10 x64
The text was updated successfully, but these errors were encountered:
Issue
Memory leaks appear in asynchronous version of
Canvas.toBuffer
method andCanvas.createPNGStream
methodCanvas.toBuffer
causes large memory leakCanvas.createPNGStream
causes small memory leakSteps to Reproduce
You need to provide some test png image to load
some_test_image.png
The script will keep saving
test.png
image in current pathRun with
--expose-gc
flag (or comment out call togc()
Your Environment
The text was updated successfully, but these errors were encountered: