**UPDATE** I just discovered my question is likely a duplicate of [If you call glBufferData after already calling it on a buffer, is there a memory leak?](https://stackoverflow.com/questions/20983416/if-you-call-glbufferdata-after-already-calling-it-on-a-buffer-is-there-a-memory?rq=1)

Hopefully my question is still useful to someone, as I give code samples, rather than merely mentioning the gl function calls, as in that Q&A.

---

I don't understand the relationship between `glGenBuffers / glBindBuffer / glBufferData` and `gldeletebuffers`.

Consider drawing a sequence of lines (a line strip). The original sequence is drawn over some number of frames, but then new user input increases the number of lines.

My first thought is to re-use the buffer object name assigned by `glGenBuffers`, when the size changes. But since the buffer size needs to be larger, I can't use the existing buffer as-is.

NOTE: At this time, I would rather not assume some "maximum size", allocate that, and then do sub-data calls for the size I currently need.

Consider code based on this example:
[When should I call glDeleteBuffers()?](https://stackoverflow.com/questions/27937285/when-should-i-call-gldeletebuffers)

If I had done these lines in an initialization function before drawing the first frame (code may not compile -- I'm concerned about the call sequence, not the exact parameters to pass -- I'm actually working in C# under Xamarin using OpenTK to access OPENGL ES 2.0, but it is easier to find examples in C++ using opengl):

```
GLuint VBO;

void init(int size, float* data) {
    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
}

```

which many frames later (or when app exits) is released via:

```
void destroy() {
    glDeleteBuffers(1, &VBO);
}

```

But now I want to have a "re\_init" function that allocates a different size, what exactly do I need to do?

I could re-assign a new VBO buffer name:

```
void re_init(newSize, newData) {
    destroy();
    init(newSize, newData);
}

```

But this seems like overkill. What is the *minimum* work that I can do? And is that any more efficient than the brute-force destroy/create-a-new-one above?

It seems that any set of calls I do works, but i don't know whether the result is leaking memory or not. I will eventually need to learn how to test for memory leaks in the environment I am in, but right now I want to get the theory right, in hopes that I will write code that is both efficient and non-leaking.

Will this leak memory?

```
void re_init(newSize, newData) {
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, newSize, newData, GL_STATIC_DRAW);
}

```

That is, I haven't done `glDeleteBuffers` on the old buffer, because doing so freed the VBO buffer name, and I am trying to find out how to not do so.

One question is whether there is a way to re-use a VBO buffer name, with data of a different size?

Or am I better off sticking to the simple model of freeing the buffer ***and its name*** every time I need to change buffer size? (That is what glDeleteBuffers seems to do.)