GPU memory leak in my visionworks app

Hi

I have written an application for 3D reconstruction using stereo camera. For camera calibration and image rectification I am using opencv and for stereo matching I am using visionworks. I sort of followed the stereo matching example given in demos provided by visionworks. In my initialization step I have the following code:

vx_image vxLeft = vxCreateImage(context, IMAGE_WIDTH, IMAGE_HEIGHT, VX_DF_IMAGE_RGB);
NVXIO_CHECK_REFERENCE(vxLeft);

vx_image vxRight = vxCreateImage(context, IMAGE_WIDTH, IMAGE_HEIGHT, VX_DF_IMAGE_RGB);
NVXIO_CHECK_REFERENCE(vxRight);

vx_image vxDisparity = vxCreateImage(context, IMAGE_WIDTH, IMAGE_HEIGHT, VX_DF_IMAGE_U8);
NVXIO_CHECK_REFERENCE(vxDisparity);

std::unique_ptr<StereoMatching> stereoMatcher_ptr = std::unique_ptr<StereoMatching>(
    StereoMatching::createStereoMatching(context, stereoParams, implementationType,
                                         vxLeft, vxRight, vxDisparity));

After rectification of both images in cuda opencv, I create vx_images and copy them to vxLeft and vxRight. Here is the member function that does that for left image:

void Stereo::cvLeftGpuMat2vxImage(vx_context context)
{
    vx_imagepatch_addressing_t addr;
    addr.dim_x = G_rectLeft.cols;
    addr.dim_y = G_rectLeft.rows;
    int Channels = G_rectLeft.step/G_rectLeft.cols;
    addr.stride_x = Channels*sizeof(vx_uint8);
    addr.stride_y = static_cast<vx_int32>(G_rectLeft.step);

    void *ptrs[] = { G_rectLeft.data };
    vx_image tmpImage = vxCreateImageFromHandle(context, VX_DF_IMAGE_RGB, &addr,
                                            ptrs, VX_MEMORY_TYPE_HOST);

    nvxuCopyImage(context, tmpImage, vxLeft);
}

I used gdb to step through the code and figured that it’s the last step of the above function where new memory is allocated. It allocates about 8MiB of memory for left image and the same goes for the right image. Thus in each iteration 16MiB of GPU memory is leaked. The application crashes after about 170 iterations. The size of my images is 1920 x 1200.

By the way, my operating system is ubuntu 14.04.2 and the GPU is GTX 1050 Ti.

Please let me know if more info is needed to solve this problem. Any help will be appreciated.

Regards

Nevermind guys, I solved it by adding

vxReleaseImage(&tmpImage);

at the end of the function.