Public bug reported: I am developing a custom C++ programs which continuously processes a huge number of short videos, so several instances of cv::VideoCapture are endlessly created and destroyed. I noticed that the memory consumption keeps growing, until after some days the process gets killed by the operating system.
After careful testing I tracked down the memory leak in cv::VideoCapture. Commenting only this object, leaving the rest of the program untouched, with the exception of those parts where this object is used, which are changed so that the job done is as close as possible (ex. using a zero-initialized cv::Mat object instead of a video frame) leads to no memory leak after hours of execution. This is portion of code where the error occurs: void procressVideo(boost::filesystem::path name) { VideoCapture video(name.string()); if(!video.isOpened()) { return; } size_t width = video.get(CV_CAP_PROP_FRAME_WIDTH); size_t height = video.get(CV_CAP_PROP_FRAME_HEIGHT); // Process frames Mat prev(height, width, CV_8UC3, Scalar(0)); Mat frame; for(long i = 0; video.read(frame); i++) { cvtColor(frame, frame, CV_BGR2RGB); frame.convertTo(frame, CV_8UC3); ... ... frame.copyTo(prev); } video.release(); boost::filesystem::remove(name); } ProblemType: Bug DistroRelease: Ubuntu 18.04 Package: libopencv-videoio3.2 3.2.0+dfsg-4build2 ProcVersionSignature: Ubuntu 4.15.0-22.24-generic 4.15.17 Uname: Linux 4.15.0-22-generic x86_64 ApportVersion: 2.20.9-0ubuntu7 Architecture: amd64 CurrentDesktop: ubuntu:GNOME Date: Mon May 28 15:02:47 2018 InstallationDate: Installed on 2018-05-24 (3 days ago) InstallationMedia: Ubuntu 18.04 LTS "Bionic Beaver" - Release amd64 (20180426) SourcePackage: opencv UpgradeStatus: No upgrade log present (probably fresh install) ** Affects: opencv (Ubuntu) Importance: Undecided Status: New ** Tags: amd64 apport-bug bionic -- You received this bug notification because you are a member of Ubuntu Touch seeded packages, which is subscribed to opencv in Ubuntu. https://bugs.launchpad.net/bugs/1773803 Title: Memory leak in cv::VideoCapture Status in opencv package in Ubuntu: New Bug description: I am developing a custom C++ programs which continuously processes a huge number of short videos, so several instances of cv::VideoCapture are endlessly created and destroyed. I noticed that the memory consumption keeps growing, until after some days the process gets killed by the operating system. After careful testing I tracked down the memory leak in cv::VideoCapture. Commenting only this object, leaving the rest of the program untouched, with the exception of those parts where this object is used, which are changed so that the job done is as close as possible (ex. using a zero-initialized cv::Mat object instead of a video frame) leads to no memory leak after hours of execution. This is portion of code where the error occurs: void procressVideo(boost::filesystem::path name) { VideoCapture video(name.string()); if(!video.isOpened()) { return; } size_t width = video.get(CV_CAP_PROP_FRAME_WIDTH); size_t height = video.get(CV_CAP_PROP_FRAME_HEIGHT); // Process frames Mat prev(height, width, CV_8UC3, Scalar(0)); Mat frame; for(long i = 0; video.read(frame); i++) { cvtColor(frame, frame, CV_BGR2RGB); frame.convertTo(frame, CV_8UC3); ... ... frame.copyTo(prev); } video.release(); boost::filesystem::remove(name); } ProblemType: Bug DistroRelease: Ubuntu 18.04 Package: libopencv-videoio3.2 3.2.0+dfsg-4build2 ProcVersionSignature: Ubuntu 4.15.0-22.24-generic 4.15.17 Uname: Linux 4.15.0-22-generic x86_64 ApportVersion: 2.20.9-0ubuntu7 Architecture: amd64 CurrentDesktop: ubuntu:GNOME Date: Mon May 28 15:02:47 2018 InstallationDate: Installed on 2018-05-24 (3 days ago) InstallationMedia: Ubuntu 18.04 LTS "Bionic Beaver" - Release amd64 (20180426) SourcePackage: opencv UpgradeStatus: No upgrade log present (probably fresh install) To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/opencv/+bug/1773803/+subscriptions -- Mailing list: https://launchpad.net/~touch-packages Post to : touch-packages@lists.launchpad.net Unsubscribe : https://launchpad.net/~touch-packages More help : https://help.launchpad.net/ListHelp