Open fancymiracle opened 5 months ago
@fancymiracle await a setTimeout before the console.info
, the Node.js never had a chance to run gc in your code
Sorry, let me provide another example. Manually, every time a press occurs, it is sent from the renderer thread to the main thread as follows:
const { createCanvas, clearAllCache } = require('@napi-rs/canvas')
let canvas1 = createCanvas(1920, 1080)
let ctx = canvas1.getContext('2d')
ipcMain.on('toMain', (event, args) => {
const rawFrameImage = ctx.getImageData(0, 0, 1920, 1080).data;
console.info(process.memoryUsage().rss / 1024 / 1024 + " MB");
clearAllCache();
})
Even after repeating this process several times, the memory continuously increases, and it does not decrease as observed in the Activity Monitor.
But if replace getImageData with canvas1.data(), which also retrieves the entire frame data, no memory leak occurs. However, this way, can only retrieve the entire frame rather than parts of it.
Probably related: drawImage()
is leaking in 0.1.52 with globalCompositeOperation = copy
let canvas1 = createCanvas(1920, 1080) let ctx = canvas1.getContext('2d') for(var i=0;i<5000;i++){ const rawFrameImage = ctx.getImageData(0, 0, 1920, 1080).data; console.info(process.memoryUsage().rss / 1024 / 1024 + " MB"); clearAllCache(); }
The memory is not released.