memory leak leaded by videocapture release method

asked 2018-09-29 21:40:45 -0600

I have a scenario that one TX2 may connect to multi rtsp camera,and each camera only need one picture every two minute.I want to save cpu utilization to support more camera in one TX2 device。I thinking I can open one camera when I need it,than I close it until next schedule time。But I get a memory leak .Sample code like this.

int main(int argc, char** argv) {
    string ss="rtspsrc location=\"rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1\" latency=0 ! decodebin ! videoconvert ! appsink";
    cv::VideoCapture *cap = new cv::VideoCapture();
    *cap=cv::VideoCapture(ss, cv::CAP_GSTREAMER);
    cap->open(ss, cv::CAP_GSTREAMER);
    while(true){
      cap->open(ss, cv::CAP_GSTREAMER);
      cv::Mat mat;
      cap->read(mat);
      mat.release();
      cap->release();
      sleep(120);
   }}

Thank you for your help.

edit retag flag offensive close merge delete

Comments

Why are you using a pointer?

This should be just fine: cv::VideoCapture cap(ss, cv::CAP_GSTREAMER);

Eduardo gravatar imageEduardo ( 2018-09-30 15:49:28 -0600 )edit

while(true){ cv::VideoCapture cap(ss, cv::CAP_GSTREAMER); cv::Mat mat; cap->read(mat); mat.release(); cap->release(); sleep(120); }}

I also try this.But the it still has memory leak .

tcwdwjj gravatar imagetcwdwjj ( 2018-10-09 01:50:44 -0600 )edit