const { createCanvas } = require('canvas');
function renderImage() {
const bgCanvas = createCanvas(800, 600);
let bgCtx = bgCanvas.getContext('2d');
bgCtx = null;
global.gc();
}
console.log('Memory usage before:', process.memoryUsage());
renderImage()
console.log('Memory usage after:', process.memoryUsage());
The above code is a minimal code sample from a possible memory leak in my discord bot. It seems to be using anywhere between 20-40mb of memory with the .getContext() method and not giving it back. Any insight would be greatly appreciated since I am completely lost here.
I am using canvas ^2.11.2
This is the memory log:
Memory usage before: {
rss: 35856384,
heapTotal: 4665344,
heapUsed: 4369736,
external: 1323854,
arrayBuffers: 10515
}
Memory usage after: {
rss: 63238144,
heapTotal: 5976064,
heapUsed: 3500384,
external: 1455306,
arrayBuffers: 10475
}
New contributor
Timbersquirrel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.