Memory leak OpenGL

Hi everyone I’m having trouble using OpenGL and dynamic draw, i’m trying to write a code in order to renderer a perlin terrain and billboards however the more different object I have to draw the faster I have a memory issue (It take like 30 seconds to catch an exeption)… I think i’m doing the buffer initialisation and update badly.

I have 3 functions :

Init buffer :

//Vertex array buffer generation
	glGenBuffers(1, &object.vertexBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, object.vertexBuffer);
	glBufferData(GL_ARRAY_BUFFER, (object.nbBillboards)* 36 * sizeof(float), nullptr, GL_STREAM_DRAW);

	//Index array buffer generation
	glGenBuffers(1, &object.indexBuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object.indexBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, object.nbBillboards * 6 * sizeof(int), nullptr, GL_STREAM_DRAW);

Update function :

//Vertex array buffer update
	glBindBuffer(GL_ARRAY_BUFFER, object.vertexBuffer);// PRINT_OPENGL_ERROR();
	glBufferSubData(GL_ARRAY_BUFFER,0, (object.nbBillboards) * 36 * sizeof(float), &object.vertexArray[0]);
	//index array buffer update 
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object.indexBuffer);
	glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, object.nbBillboards * 6 * sizeof(int), &object.indexArray[0]);

And a draw

	//Buffer binding
	glGenVertexArrays(1, &object.VAO);
	glBindBuffer(GL_ARRAY_BUFFER, object.vertexBuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object.indexBuffer);

	//Attrib pointers
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), nullptr);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), buffer_offset(3 * sizeof(float)));
	glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), buffer_offset(6 * sizeof(float)));

	float c[4]{ 0.0f,0.0f,0.0f,0.0f };
	glUniform4fv(get_uni_loc(programId, "color"), 1, c);
	GLuint text_id = glGetUniformLocation(programId, "texture");
	glUniform1i(text_id, texture);

	glDrawElements(GL_TRIANGLES, 6 * object.nbBillboards, GL_UNSIGNED_INT, nullptr);

I think that the draw function is causing the memory leak but i’m not an expert I learned OpenGl alone.
Do yu guys have a clue on what i’m doing wrong ?
Thank you in advance for your help.

Sorry for uploading my code like that but i’m struggling with that issue for many days… And sorry for my english :smiley:

You should be doing all of that in the initialiser, not the draw function. The draw function should just be calling glBindVertexArray.