memory problem?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
c.h.r.i.s
Posts: 41
Joined: Mon Jan 22, 2007 8:38 pm

memory problem?

Post by c.h.r.i.s »

Hi! Iam using Microsofts Visual c++. I have createt a windows forms application with a simple button. If i klick the button irrlicht wil create a window and load the world.

When i run the application and open the windows task manager i can see that my application uses 21,532k of Memory. And if i click my irrlicht button the Memory increases to 76,600k.

But when i close the irrlicht window the Memory of my application is not 21,532k again. Its about 33,000k. If i open and close the irrlicht window any times again the memory useage of my program becommes bigger and bigger.

I think there are undeletet irrlicht variables. I only use device->drop()
to destroy irrlicht.

Any ideas?
Strong99
Admin
Posts: 687
Joined: Fri Mar 31, 2006 7:06 pm
Location: Netherlands
Contact:

Post by Strong99 »

you do drop but what else?

code may help of your onevent,
c.h.r.i.s
Posts: 41
Joined: Mon Jan 22, 2007 8:38 pm

Post by c.h.r.i.s »

hm..ok...here is the code: (i know that i have postes this code already in other topics...but i hope it will help other people too ;-) )

At first i have createt a struct:

Code: Select all

struct world
{
irr::IrrlichtDevice* device;
irr::gui::IGUIEnvironment* guienv;//playergui
ISceneManager* smgr;
IVideoDriver* driver;
irr::newton::IWorld* p_world;
irr::newton::IBody* fairy_body;//player collision body from newton
irr::scene::CCameraRPGSceneNode* mycam;
irr::scene::ITriangleSelector* selector;
irr::scene::ISceneNode* selectedSceneNode;//for objects selection
irr::scene::ISceneNode* lastSelectedSceneNode;//for objects selection
irr::scene::IAnimatedMeshSceneNode* fairy;
IGUIListBox* console;//console
irr::gui::IGUIButton* button_quit;
irr::gui::IGUIButton* button_tutorial;
irr::gui::IGUIButton* button_takephoto;
irr::gui::IGUIButton* button_editor;
irr::gui::IGUIButton* button_normalmode;
irr::gui::IGUIButton* button_newobject;
irr::gui::IGUIButton* button_deleteobject;
irr::gui::IGUIButton* button_texture;
irr::scene::IAnimatedMeshSceneNode* mymodel;
int mouse_over_gui;
int file_dialog_open;
int object_count;//how many objects are currently loaded
int editor_active;
int file_open_type;
int object_selected;
ISoundEngine* mysoundengine;//sound
VxCompass* pgCompass;//compass
};//end struct
Then i wrote 3 functions that will make, run and destroy world:

Code: Select all

void init_world(world *myworld, System::String^ worldname)
{
//load device, world, player ,newton, irrklang, etc
}

void run_world(world *myworld)
{
while(myworld->device->run())
	{...}
}

void destroy_world(world *myworld)
{
myworld->mysoundengine->stopAllSounds(); 
myworld->device->drop();
myworld = NULL;
}

ok. and now whith the click on my button i call this:

Code: Select all

world theworld;
init_world(&theworld,worldname);
run_world(&theworld);
destroy_world(&theworld);
thats it. After closing the irrlicht window destroy_world will be called. And after that the main program is still running and i can click the button again.
LwSiX
Posts: 22
Joined: Wed Jan 17, 2007 2:24 pm

Post by LwSiX »

im having a similar issue, my game is using a ridiculous amount of memory in the main game loop. It is very strange.
Sparky
Posts: 23
Joined: Wed Apr 25, 2007 5:57 pm
Location: England
Contact:

Post by Sparky »

c.h.r.i.s,

Need much more information than that - the code that is most likely offending is within the main loop, or in an event handler. It's unlikely to be at the beginning or end of a game - as the memory leak is apparent in the middle of the game.

Cheers
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You should be destroying/deallocating/dropping everything that you have a pointer to that needs to be cleaned up. If you have grabbed the gui elements and scene nodes, you should drop them. You should also have code to clean up your newton world and body, the sound engine, the compass.

You can enable the debug heap and at program exit it will tell you the file name, line and allocation number for the failed allocation. You can use that information to figure out where the memory leak is coming from. You can find more information about using the debug heap here http://msdn2.microsoft.com/en-us/librar ... s.71).aspx.

You could also use the Rational Purify tool to instrument your code and to help you locate your memory leaks. It is very easy to use and doesn't usually require you to make changes to your source code or project in any way.
Post Reply