Possible memory leak using opencv VideoCapture with gstreamer backend

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
Jetson Nano Developer Kit
• Gstreamer Version
1.14.5
• Opencv Version
4.7.0
• Python Version
3.6.9
• JetPack Version (valid for Jetson only)
4.6
• Issue Type( questions, new requirements, bugs)
Possible memory leak
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)

Minimal python script:

def mem_available_mb():
    with open('/proc/meminfo') as file:
        mem_available_in_kb = None
        mem_total_in_kb = None
        for line in file:
            if 'MemTotal' in line:
                mem_total_in_kb = int(line.split()[1])
                if mem_available_in_kb is not None:
                    print("used:", mem_total_in_kb / 1024)
            elif 'MemAvailable' in line:
                mem_available_in_kb = int(line.split()[1])
                break
            if mem_available_in_kb is None or mem_total_in_kb is None:
                continue

    return mem_available_in_kb / 1024

def init_cam_streams():
    cams = []
    for i in range(2):
        cams.append(cv2.VideoCapture(i, cv2.CAP_GSTREAMER))
    return cams

if __name__ == "__main__":
    file_name = "test gstreamer minimal.txt"
    cams = init_cam_streams()
    while True:
        try:
            a = mem_available_mb()
            with open(file_name, "a") as f:
                f.write(str(a) + "\n")
            time.sleep(10)
            print(len(cams))
        except KeyboardInterrupt:
            break

While running this script, available memory decreases with ± 1MB/min. Switching to FFMPEG backend causes the problem to disappear. Any suggestions?

There is no DeepStream plugin in your code. We suggest you open a topic on the OpenCV Forum. Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.