Deleting buffers causing performance issues

I have a very large scene which I am viewing portions of at a time. I am streaming the meshes in for different views. Each mesh reads its vertex and index data of of disk on the background queue, then loads that data into VBOs on the main thread, and deletes the data they read. When the next scene is loaded the previous meshes delete their VBOs. After doing this a couple of times the framerate of any given scene drops by a good 50%. I am confident I am not leaking memory, I can load and reload many scenes without getting any memory warnings. If I don’t delete the mesh data between scenes the performance stays consistent. But I ultimately want to have much larger scenes on disk than I am viewing at any one time.
My target platform is the ipad2.
Do you have any idea what my problem might be? Could it be some kind of memory fragmentation?
I’ve tried not using VBOs but then the performance is just rubbish anyway.
I’ve tried not deleting the memory from main memory (what is the significance of this on a device that has shared memory, by the way?), made no difference.
I tried creating a memory allocator that allocates enough memory at startup for any given scene, that the meshes then use for reading off disk. So no main memory allocation or deleting just VBO deleting. Still no difference.
The fundamental problem seems to be deleting and adding many VBOs.
Any ideas would be much appreciated.

Have you tried orphaning the buffer’s data store rather than deleting the buffer, eg.


and then re-using the buffer name rather than creating a new one?glBufferData( GL_ARRAY_BUFFER, 0, 0, GL_STATIC_DRAW );

and then re-using the buffer name rather than creating a new one?

Hey Nick :slight_smile:

Apple deals with the drivers for iOS so you should probably go to them with this issue. If you have a version for Android or one of our other platforms then we might be able to investigate further.

I can only speculate, but it may be that there are memory leaks in the driver - I’d have though Apple’s Leaks instrument would at least show if this is the case (and verify that you have none in your application).

Have you tried using very small meshes? If this ups the number of VBO uploads before you encounter the issue then it might show that it is a leak or similar.

What happens if you delete all the VBOs and then reload?

If you don’t need VBO data after it’s been uploaded to GL then you might as well save memory and delete it from your own data structures.

Actually it had nothing to do with the mesh streaming. Some meshes enabled vertexattrib tangent array and never disabled them, so whenever anything was rendering without them afterwards it ran like a  dog - doh!
Thanks for all your help!

On the subject though is there any point deleting mesh data from memory after loading into vertex buffers? Sometimes it’s useful to keep around for collision and such. If it’s all the same memory are you actually freeing anything?

Easy thing to miss, I suppose - glad you worked it out.

If you need mesh data for other reasons (and you have memory budget spare for it) by all means keep it around. If you need the spare memory then you can delete the original data after it’s been uploaded to the VBO and the VBO will still render from the VBO data that the driver has to maintain in case you do exactly that.