OpenCL clReleaseContext


I’m writing a library in C++ for general purpose OpenCL work in our lab. Everything is working perfectly with all functions calling CL_SUCCESS. The Context, Queues, Memory Objects, and Devices are all created successfully. When it comes time to cleanup all the OpenCL objects, everything also returns CL_SUCCESS.

However, I noticed that the cl_context, when created takes around 15MB. When clReleaseContext is called, this 15MB is not deleted until I completely close down my DLL and and program calling it.

I understand that clCreateDevice does an implicit clRetainContext, but clReleaseContext should delete the context regardless.

Anyone else having problems with this? Is this a bug or working as intended? This is with the NVIDIA CUDA 5.0 kit with a OpenCL 1.1 on a GTX 560 Ti.


You can check if there are reference count leaks by querying CL_CONTEXT_REFERENCE_COUNT (using clGetContextInfo) before calling clReleaseContext. I don’t know about the driver internals, but I imagine the driver might allocate some memory for internal use the first time you create a context, but which isn’t specific to that context and so doesn’t get cleaned up.