Memory leak when using python VPI bindings

Hello. When I use a simple example like this:

import os
os.environ['OPENBLAS_CORETYPE'] = 'ARMV8'
import cv2
import sys
import vpi
import numpy as np
import time
from argparse import ArgumentParser
import gc
backend = vpi.Backend.CUDA
print('1')
inVideo = cv2.VideoCapture(1)
inVideo.set(cv2.CAP_PROP_FRAME_WIDTH, 480)
inVideo.set(cv2.CAP_PROP_FRAME_HEIGHT, 640)
inVideo.set(cv2.CAP_PROP_FPS, 30)  
if int(cv2.__version__.split('.')[0]) >= 3:
     extOutputVideo = '.mp4'
     fourcc = cv2.VideoWriter_fourcc(*'avc1')
     inSize = (int(inVideo.get(cv2.CAP_PROP_FRAME_WIDTH)), int(inVideo.get(cv2.CAP_PROP_FRAME_HEIGHT)))
     fps = inVideo.get(cv2.CAP_PROP_FPS)
else:
     # MP4 support with OpenCV-2.4 has issues, we'll use
     # avi/mpeg instead.
     extOutputVideo = '.avi'
     fourcc = cv2.cv.CV_FOURCC('M','P','E','G')
     inSize = (int(inVideo.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)), int(inVideo.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)))
     fps = inVideo.get(cv2.cv.CV_CAP_PROP_FPS)
print(inSize)
outVideo = cv2.VideoWriter('denoised_python'+str(sys.version_info[0])+'_'+'cuda.avi',
                             cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, inSize)  
curFrame = 0
new_frame_time = 0
font = cv2.FONT_HERSHEY_SIMPLEX
prev_frame_time = 0
while True:
     curFrame+=1
     print("Frame: {}".format(curFrame))
     ret, cvFrame = inVideo.read()
     print(cvFrame.shape)
     if not ret:
         break
     start_time = time.time()
     with vpi.Backend.CUDA:
            frame = vpi.asimage(cvFrame).convert(vpi.Format.NV12_ER)
            denoised = frame.eqhist()
            denoised = denoised.convert(vpi.Format.RGB8)
     print("--- %s seconds ---" % (time.time() - start_time))     
     with denoised.rlock():
         frame=denoised.cpu()
         new_frame_time = time.time()
         fps = 1/(new_frame_time-prev_frame_time)
         prev_frame_time = new_frame_time
         fps = str(int(fps))
         cv2.putText(frame, fps, (7, 70), font, 3, (100, 255, 0), 3, cv2.LINE_AA)
         #outVideo.write(frame)
         cv2.imshow('Input', frame)
     c = cv2.waitKey(1)
     if c == 27:
        break

I get a memory leak.
I could not find a proper help for the Python API

Hi,

Thanks for reporting this.
We are checking this internally. Will share more information with you later.

Hi,

Confirmed that we can reproduce this issue in our environment.
Our internal team is working on it and share more information with you later.

Thanks.

Hi,

Thanks for your patience.

Our internal team is working on this issue.
Currently, you can use vpi.clear_cache() as a temporal solution to make sure the buffer is released.

For example:

while True:
    ret, cvFrame = inVideo.read()
    ...

    with vpi.Backend.CUDA:
        frame = vpi.asimage(cvFrame)
        ...
        vpi.clear_cache()

Thanks.