correctly deleting buffers

Hi all.
i have a problem with this code:


//m_buffer is defined elsewhere
cl::Buffer result_zb = cl::Buffer(context, CL_MEM_WRITE_ONLY, res_zb->Id(), &ciErrNum);

cl::Kernel kernel = OCLUtils::GetInstance()->getCutKernel();
kernel.setArg(0, m_buffer);
kernel.setArg(1, result_zb);

cl::vector<cl::Memory> buffers;
buffers.push_back(m_buffer);
buffers.push_back(result_zb);
queue.enqueueAcquireGLObjects(&buffers, NULL, NULL);

//workgroup sizes are defined elsewhere
cl_int ciErrNum = clEnqueueNDRangeKernel(m_queue(), kernel(), 1, NULL, global_workgroup_size, local_workgroup_size, 0, NULL, NULL);
		
queue.enqueueReleaseGLObjects(&buffers, NULL, NULL);
		
clFlush(queue());

when i execute this code for benchmark purposes, i need to execute it for many times sequentially to get significant running times.
the problem is that, after a few repetitions that works correctly, i get a CL_OUT_OF_HOST_MEMORY error
while executing cl::Buffer result_zb = cl::Buffer(context, CL_MEM_WRITE_ONLY, res_zb->Id(), &ciErrNum);

i think this is because memory coming from result_zb is not freed coorectly, so i have a memory leak and my card’s RAM
fills up.

how can i correctly free the memory? any hints?

Maybe try following this up with clFinish?

http://www.khronos.org/registry/cl/sdk/ … Flush.html indicates there is no completion guarantee on clFlush.

In addition, is this your real code or you are you also capturing error codes when you call clFlush? Make sure it CL_SUCCESS (e.g. == 0).

hi and thanks for the answer.
unfortunately that hasn’t worked.
do you know where there could be a memory leak or how i can find out where it is?

now i checked for the result of clFinish and it’s CL_SUCCESS :confused:

I looked in a function I made to clear my memory buffers / images. I have never actually checked to see if the video card memory is freed, but maybe you can test it for me ;).


bool XXXXXXXXX::releaseMemObject(cl_mem &obj)
{
  cl_int   err = NULL;
  bool     returnStatus = true;    // true if successful

  if (obj != NULL)  // This means it has been initialized
  {
    err = clReleaseMemObject(obj);
    if (err != CL_SUCCESS)
    {
      cout << "Error releasing variable
";
      returnStatus |= false;
    }
    else
      obj = NULL; /* memory was released, re-initialize pointer to NULL */
  }

  return returnStatus;
}