# terrible memory leak

**URL:** <https://forums.developer.nvidia.com/t/terrible-memory-leak/13178>\
**Category:** CUDA Programming and Performance\
**Created:** [November 11, 2009, 12:39am UTC](https://forums.developer.nvidia.com/t/terrible-memory-leak/13178 "2009-11-11T00:39:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfarrell](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfarrell](https://forums.developer.nvidia.com/u/mfarrell)\
**Post date:** [November 11, 2009, 12:39am UTC](https://forums.developer.nvidia.com/t/terrible-memory-leak/13178/1 "2009-11-11T00:39:44Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![mfarrell](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfarrell](https://forums.developer.nvidia.com/u/mfarrell)\
**Post date:** [November 11, 2009, 3:09am UTC](https://forums.developer.nvidia.com/t/terrible-memory-leak/13178/2 "2009-11-11T03:09:25Z")

</div>

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.
