New game memory leaks

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!

New game memory leaks

Postby jwatson1993 » Sun Jan 22, 2012 6:13 am

In my game, if the user presses escape, they will return to the main menu, where they can choose to make a new game. I'm not deleting the textures and meshes from memory because Irrlicht checks for them beforehand. What all do I have to do to make sure memory doens't leak, because for each iteration ~400k of memory(according to the task manager) is being created. Here's the code for the quitting:

cpp Code: Select all
 
        //clearPhysics();
                gameState = G_MAIN_MENU;
                smgr->clear();
               
                SKeyMap* keyMap = new SKeyMap[6];//changes the keymap to something usable
                        keyMap[5].Action = EKA_MOVE_FORWARD;
                 keyMap[5].KeyCode = KEY_UP;
                 keyMap[0].Action = EKA_MOVE_FORWARD;
                 keyMap[0].KeyCode = KEY_KEY_W;
                 keyMap[1].Action = EKA_MOVE_BACKWARD;
                 keyMap[1].KeyCode = KEY_KEY_S;
                 keyMap[2].Action = EKA_STRAFE_LEFT;
                 keyMap[2].KeyCode = KEY_KEY_A;
                 keyMap[3].Action = EKA_STRAFE_RIGHT;
                 keyMap[3].KeyCode = KEY_KEY_D;
                                 keyMap[4].Action = EKA_JUMP_UP;
                 keyMap[4].KeyCode = KEY_SPACE;
                camera = smgr->addCameraSceneNodeFPS(smgr->getRootSceneNode(), 50.0f,.1f, -1, keyMap, 6, false, 10.f);
                device->getCursorControl()->setVisible(true);
                guienv->getRootGUIElement()->setVisible(true);
 


If my variables are self-documenting ask me to explain what they are. Whenever this is called there isn't a drop in memory usage, either, so something isn't being cleared.
jwatson1993
 
Posts: 31
Joined: Fri Nov 04, 2011 12:15 am

Re: New game memory leaks

Postby hendu » Sun Jan 22, 2012 8:39 am

I don't see you deleting keyMap anywhere. Other than that, a valgrind log please (or your favorite memory leak detector tool).
hendu
 
Posts: 1556
Joined: Sat Dec 18, 2010 12:53 pm

Re: New game memory leaks

Postby hybrid » Sun Jan 22, 2012 11:49 am

If you add cameras and other scene graph elements each time without removing them, you'll also see an increase in memory usage.
hybrid
Admin
 
Posts: 13943
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Re: New game memory leaks

Postby jwatson1993 » Sun Jan 22, 2012 8:31 pm

Cameras are nodes, though, and shouldn't clear() delete their memory? Keymap shouldn't be an issue, should it?
jwatson1993
 
Posts: 31
Joined: Fri Nov 04, 2011 12:15 am

Re: New game memory leaks

Postby hybrid » Sun Jan 22, 2012 8:59 pm

Oh yes, seem to have missed the early lines of the code fragment. That should be enough to remove all scene nodes, including cameras
hybrid
Admin
 
Posts: 13943
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Re: New game memory leaks

Postby hendu » Mon Jan 23, 2012 4:50 pm

Well if you're creating a new keymap each time, and not deleting it, that's an obvious leak?
hendu
 
Posts: 1556
Joined: Sat Dec 18, 2010 12:53 pm


Return to Advanced Help

Who is online

Users browsing this forum: No registered users and 1 guest