Ask Your Question

Revision history [back]

memory leak leaded by videocapture release method

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.