views:

32

answers:

1

Right now, I'm playing with OpenGL ES on the iPhone using Oolong Engine. This might be a silly question, but how necessary is it to clean up after OpenGL when the app exits? My problem is that I have a static vector that manages loading models, and loosely ensures that models aren't loaded twice. Because of this, all the handles to the VBOs and textures are stored in Model objects in a static map<Model>. When the app closes down, the map doesn't seem to call the destructors on the individual Model objects, so they don't end up calling glDeleteBuffers().

My question is, is this entirely necessary, if the application is small enough that I'm never unloading and reloading models from memory during runtime? Or does OpenGL just take care of all that for me? I could make a static CleanUp() function that gets called from the application's dealloc, but is that worth it?

+3  A: 

When the actual app exits, all resources get cleaned up with it, including all GL stuff. Don't worry, the OS wouldn't let your rogue app accidentally leak a bunch of GPU resources.

Managing resources in Open GL in general is something you should do of course during the course of your app's life, but it sounds like you know how to do this.

quixoto
Great! Is it considered "best practices" to make sure it releases it, or is it one of those things that is totally fine to not worry about?
Perrako
Sure, this sort of thing is a best practice, but usually in the context of all your management data structures anyways. In other words, if you have good collections and containers for all your data anyways, their normal cleanup stuff (via destructors or what have you) is likely to take care of resources anyways. Outside of that, when the process is torn down, don't worry about it. I would say a bad practice is intentionally writing code that doesn't do cleanup. (Leaving stuff out of dealloc methods, etc, just because you "know you can".)
quixoto