#StackBounty: #node.js #opencv #mat #opencv4nodejs Why OpenCV Mat creates memory leaks?

Bounty: 50

Not sure if this is relevant, but I’m using opencv4nodejs for my project, and I did run in this situation where if I don’t call .release() on each Mat object, the memory consumption goes up ~10MB/s.

This simple example code will crate the issue.

function loop(camera, display)
{
    let mat = camera.read();

    let grey_mat = mat.bgrToGray();

    loop(camera, display);
}

Where as, this one fixes the problem:

function loop(camera, display)
{
    let mat = camera.read();

    let grey_mat = mat.bgrToGray();

    grey_mat.release();

    mat.release();

    loop(camera, display);
}

If I search for why OpenCV Mat object causes leaks I get answers where people say that Mat is capable of taking care of memory usage on its own.

If the last statement is true, what am I doing wrong? And if I’m not doing anything wrong, why do I have to explicitly tell a Mat object to release its memory? Or, is there a potential issue with the npm module opencv4nodejs itself?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.