SFML community forums

Help => Graphics => Topic started by: netrick on July 23, 2013, 09:31:39 am

Title: Vertex array questions
Post by: netrick on July 23, 2013, 09:31:39 am
1) Is vertex array RAII object? I mean when I have a vector of vertex arrays and I call "vector.clear()", will there be any memory leaks?

2)

Quote
void sf::VertexArray::clear()

Clear the vertex array.

This function removes all the vertices from the array. It doesn't deallocate the corresponding memory, so that adding new vertices after clearing doesn't involve reallocating all the memory.

Does this mean that if I don't add new verticles after clearing vertex arrays there will be memory leak?
Title: Re: Vertex array questions
Post by: Laurent on July 23, 2013, 09:43:28 am
Quote
1) Is vertex array RAII object? I mean when I have a vector of vertex arrays and I call "vector.clear()", will there be any memory leaks?
Yes, of course VertexArray releases its memory when it's destroyed. It would be a major mistake otherwise.

Quote
Does this mean that if I don't add new verticles after clearing vertex arrays there will be memory leak?
No. It just means that the memory will remain allocated until the vertex array is destroyed. VertexArray is just a std::vector, so if you know how a vector works then you know everything about VertexArray ;)