# How to deallocate memory for vertex buffer objects

class A {
GLuint vao, vbo, ebo;

A() {
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glGenBuffers(1, &ebo);

}

~A() {
DeallocateBuffers();
}
}


When an object of that class is destructed I would like to free the memory allocated by the buffers. I can't figure out how do this correctly. This is what I tried but it doesn't seem to be correct.

void DeallocateBuffers() {
glDeleteVertexArrays(1,&vao);
glDeleteBuffers(1,&ebo);
glDeleteBuffers(1,&vao);
}

• Schouldn't you use vbo instead of vao in the second glDeleteBuffers call? – wychmaster Nov 22 '20 at 11:17
• @wychmaster Yeah sorry it should be vbo – Lenny White Nov 22 '20 at 14:25
• @LennyWhite: "but it doesn't seem to be correct." ... why not? – Nicol Bolas Nov 23 '20 at 14:51