When i release the gpumat from bufferPoll,but data is still in memory

I release the im_source, and create a new GpuMat from BufferPool.
But the mat_source still in memory.Is this Bug or Design?

#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core/cuda.hpp>


using namespace std;
using namespace cv;
using namespace cv::cuda;


int main() {

    cv::cuda::setBufferPoolUsage(true);
    cv::cuda::setBufferPoolConfig(cv::cuda::getDevice(), 1024 * 1024 * 64, 1);

    cv::cuda::Stream stream;
    cv::cuda::BufferPool pool(stream);

    Mat mat_source = imread("test.png", cv::IMREAD_COLOR); //Any picture is OK

    GpuMat im_source = pool.getBuffer(mat_source.size(), CV_8UC3);
    im_source.upload(mat_source);
    im_source.release();

    GpuMat im_search = pool.getBuffer(10, 10, CV_8UC1);
    Mat outMat;
    im_search.download(outMat);
    cout << outMat << endl;
    return 0;
}
1 Like

please, NO screenshots / images of code or errors here.

be so nice, to remove that, and paste your code as text, thank you.

1 Like

:joy: i have now added code example,I’ll remember it

1 Like

Can you clarify what you are hoping to see when releasing im_source and creating im_search?

I have just checked and it appears that the memory allocated by
cv::cuda::setBufferPoolConfig is not released when it goes out of scope. This may be by design.

That said I am not sure what you are hoping to see when releasing im_source and creating im_search. I would expect the total free memory on the device to remain constant because it was allocated in the call to cv::cuda::setBufferPoolConfig and creating and destroying GpuMat’s simply uses some of that pre-allocated memory.

outMat is all zero when use default allocator. this is different from bufferpool
I hope the bufferpool and the default allocator should be the same.
Buf I don’t know if bufferpool designed like this

#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core/cuda.hpp>


using namespace std;
using namespace cv;
using namespace cv::cuda;


int main() 
{
    cv::cuda::setBufferPoolUsage(true);
    cv::cuda::setBufferPoolConfig(cv::cuda::getDevice(), 1024 * 1024 * 64, 1);

    cv::cuda::Stream stream;
    cv::cuda::BufferPool pool(stream);

    Mat mat_source = imread("test.png", cv::IMREAD_COLOR); //Any picture is OK

    GpuMat im_source = GpuMat(mat_source.size(), CV_8UC3);
    im_source.upload(mat_source);
    im_source.release();

    GpuMat im_search = GpuMat(10, 10, CV_8UC1);
    Mat outMat;
    im_search.download(outMat);
    cout << outMat << endl;
    return 0;
}

What value would you expect outMatto be? With BufferPool outMat is zero for me are you expecting it to contain some of the values left over from im_source?

I hope BufferPool outMat is zero. but now i got some values from im_source

Ignore my previous comment.

All alocations as far as I am aware use a variant of cudaMalloc which states in the documentation that

The memory is not cleared.

Therefore it is not safe to make any assumptions regarding the initial values of any empty GpuMat containers.

1 Like