Very slowly increasing & resetting memory in C++ and OpenGL? (VS Debugger)

295 views Asked by At

memory

My C++ program's memory very slowly increases, then after awhile (minutes) after reaching a certain point (60MB) it decreases by ~12 MB. This repeats indefinitely while my program is running. Is this, itself, a problem?

It appears to be related to this OpenGL-related function I am calling many times per frame, as calling it more times per frame makes memory increase faster and still decrease again after reaching 60MB. I am unsure if this counts as a leak, and I am also unsure if given enough time, memory would slowly reach over 60MB, as I have run it while checking this issue, for up to 10 minutes at a time.

// vertices is just a GLfloat[] and the only other part of the function

glBindVertexArray(this->vao);

glBindBuffer(GL_ARRAY_BUFFER, this->vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW); // i believe it is this line

glBindVertexArray(0);
2

There are 2 answers

1
AudioBubble On BEST ANSWER

glBufferData() doesn't actually upload data to the GPU immediately in most drivers, the operation gets put in a queue and gets eventually flushed.

In order for this to work, the driver has to make a copy of your vertices because it has no way of knowing whether the data will still be around by the time its command queue is flushed.

Beyond that, whatever memory strategy is used by the OpenGL driver will determine how and when that memory gets released/reused, so the behavior you are seeing is not necessarily a problem.

This is all assuming you don't have an additional memory leak in your code, since we can't see how vertices is allocated.

0
Jadh4v On

You do not have to transfer vertex data during every draw call. glBufferData() should be called only once for a VBO. Later, you simply bind the corresponding VBO when you want to bind it to vertex array or vertex attribute.