'OpenCV C++ memory leak issue

Just see the below code snippet -

# include "opencv4/opencv2/opencv.hpp"
# include "iostream"
int main() {
    while (true) {
        cv::Mat* mat = new cv::Mat(2000, 2000, CV_8UC3);
        std::cout << "mat size" << mat->size() << std::endl;
        mat->release();
        std::cout << "mat size after" << mat->size() << std::endl;
    }
}

Problem after running is - ram keep filling. I have 48 gb of ram, which got filled in just some minutes as the loop runs.

If i am releasing the memory, then why it keeps acquiring my ram.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source