I'm having some problems regarding memory management in an application I'm working on. The world is structured in locations, and each location can contain triggers, objects, etc. For now only triggers are implemented. The problem is that when a location is cleared and a new one is loaded I'm loosing some memory.
First I don't know if this technique for releasing locations is good:
- the scene node is removed with remove()
- for every meshbuffer in the locations mesh the textures are removed:
Code: Select all
ITexture *toRemove;
toRemove = location->mesh->getMeshBuffer(i)->getMaterial().getTexture(0);
//remove textures
if (toRemove) driver->removeTexture(toRemove);
toRemove = location->mesh->getMeshBuffer(i)->getMaterial().getTexture(1);
//remove lightmaps
if (toRemove) driver->removeTexture(toRemove);
Code: Select all
location->smgr->getMeshCache()->removeMesh(location->mesh);
Code: Select all
const bool isRTT = Material.getTexture(i) && Material.getTexture(i)->isRenderTarget();I've tried to find the leak using the the VC built in debugger, but when the application closes, the memory dump is very very large, and also shows data from the engine, so finding the bug for my tiny application would be very hard.
The structures in question:
Code: Select all
typedef struct
{
CTriggerNode *node;
s32 majorType;
s32 minorType;
stringw action;
stringw antiAction;
bool actionState;
stringw description;
stringw name;
bool state;
} STrigger;
typedef struct
{
ISceneNode *node;
ISceneManager *smgr;
IMesh *mesh;
ISceneNode* skyBox;
irr::core::array < STrigger* > triggers;
} SLocation;
Unrelated to Irrlicht:
Should I avoid using stuff like string/wstring/vector from the std library, or can they be used without risk of memory loss. I've tried replaceing std::vector with irr::core::array in the location stucture but the problem persists.
And lastly, what approach would be better: Focus on actually building the application, implementing memory management as best I can or continually check for memory leaks at each step and do not advance until every problem is solved.
This is a very frustrating problem, so any help would be greatly appreciated.
