Bonzai Engine Forum

Bonzai Engine & Tools => Bonzai Engine => Topic started by: Angelo on June 26, 2012, 01:57:09 PM

Title: Model unloading
Post by: Angelo on June 26, 2012, 01:57:09 PM
What is the correct way of unloading my models? In my Android application, I have an Activity which loads models when it starts. When I leave the Activity, I want the models to be unloaded. Otherwise, when I get back to the Activity, since I will load new models, I will risk getting OutOfMemory errors. I thought I could call "assets.unloadAll(IGL igl)" inside the "onStop()" method of my Activity, but I don't know how to access that IGL variable, which seems to be accessible only as a parameter in methods like "render".
Title: Re: Model unloading
Post by: jerome_j on June 26, 2012, 08:03:18 PM
All method which requires an IGL object must be executed in the opengl thread (ie when opengl context is current) since they will call opengl methods.

AssetManager.unloadAll unload all textures and shaders from the gpu. In addition, you'll have to also unload the model mesh from gpu with RendererPipeline.release(model).
If your activity destroy the GLSurfaceView, the opengl context will also be destroyed (ie all data loaded to the gpu).

Additionnally, if you want to destroy Model from main memory, just make sure the AssetManager is not reference anymore and let the GC garbage everything.