terrible memory leak

The problems keep on coming. My latest issue:

this is happening on both linux and windows (mac does it right), with two separate video cards. please help me

cudaGLUnregisterBufferObject does NOT free up GPU memory that cudaGLRegisterBufferObject allocates.

I have a vbo class that upon construction, allocates vbos on construction and deallocates them on destruction. I was noticing it wasn’t giving the memory back. Finally I narrowed it down to the simplest example of the problem:

static void print_mem()

{

  CUresult res;

  uint free, total;

  res = cuMemGetInfo(&free, &total);

  cout << "Free memory: " << (free>>20) << " MB" << endl;  

}

//ignore the safecall routines, they do the same thing as cutil but put up a dialog box

static void test()

{

  const size_t num_verts = 1024*1024*50;

  print_mem();

GLuint vbo = 0;

glGenBuffers(1, &vbo);

  glBindBuffer(GL_ARRAY_BUFFER, vbo);

  glBufferData(GL_ARRAY_BUFFER, num_verts*sizeof(float)*4, 0, GL_DYNAMIC_DRAW);

  glBindBuffer(GL_ARRAY_BUFFER, 0);

  cbctSafeCall(cudaGLRegisterBufferObject(vbo));

print_mem();

cbctSafeCall(cudaGLUnregisterBufferObject(vbo));  //doesn't free a damn thing

  print_mem();

glDeleteBuffers(1, &vbo);  

  print_mem();

}

this code produces:

Total memory: 1023MB

Free memory: 852MB

Free memory: 852 MB

Free memory: 52 MB

Free memory: 52 MB

Free memory: 52 MB

Okay so this is getting even more frustrating. At some random point in my app I finally get the memory back. However I cannot force this update to happen directly after unregistering the vbo. I need to do this because if I try to make an allocation that exceeds what cuda thinks it has left, it’ll crash with “out of memory”.

Essentially the driver api is forgetting to update heap after unregistering.