|
Terminating processes is asking for grief. If you call TerminateProcess the code doesn't get a chance to cleanup after itself.
Steve
|
|
|
|
|
A friendlier approach would be to enumerate the top-level windows and send SC_CLOSE command messages to them. This gives the user a chance to save his work.
Software Zen: delete this;
|
|
|
|
|
General Problem: I am having a bit of trouble figuring out why my program's memory usage continues to grow during run-time.
Basic Information: Visual Studio 2005
Project: Game
Libraries: SDL and GLUT
Tools: Visual Leak Detector and Application Verifier
Comment:
I think I should first state that I am using the task manager to monitor memory usage (so perhaps that's my first mistake), suggestions on a different tool are welcome and wanted.
Low-Down:
I have been creating a game that involves eight or more classes (thus far) and basically is run through a series of 'scenes' which are themselves unique class objects designed for their appropriate section (exp: TITLE,GAMESETUP,OPTIONS). This error only occurs with my 'world' scene which is the main gameplay scene that must last untill the player wants to stop playing the game. Within this scene, the player can click the menu button which creates a new 'menu' class object. When this object is first created with 'new' (from the gameplay scene object), it takes up about 200k due to mostly dynamically loaded textures. When they choose to return to the game from the menu, I delete the textures and then the menu object itself. However, memory usage only drops 20k. There is a similiar problem with the only other class object created by the gameplay scene. I haven't actually added much game play content, i've just been building the engine until thus far. I assume if the class object takes 200k to create, once it's properly deleted it should return that 200k. I tried clicking the menu and returning multiple times and the usage kept rising and rising.
I have used tools to check for memory leaks and it tells me none exist in my program. I have tried the program in debug mode and release mode and it still occurs. Can anyone give me some ideas for what I should look out for, or some sort of memory leak that isn't detected by the software.
|
|
|
|
|
Are you compiling for managed code? If so, the memory usage won't go down until the garbage collector kicks in.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Well, I am using Visual Studio 2005, so yes I am. I didn't see the other c++ section till now, so my mistake. Perhaps the 20k that seems to be coming back is simply local variables being used and let go instead. Do you know what a person should do to call the garabage collection early or as needed?
-- modified at 0:10 Tuesday 14th March, 2006
I see a tutorial from codeproject, none the less
http://www.codeproject.com/managedcpp/garbage_collection.asp
I'll give it a shot and post back the findings.
-- modified at 12:06 Tuesday 14th March, 2006
After reviewing my code, it appears I wasn't using managed code at all. So this solution will not fix the problem.
|
|
|
|
|
The C/C++ heap generally shrinks only under certain conditions. 200k is perfectly acceptable. The only real concern is if it allocates an additional 200k each time.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
That is exactly the problem,
each time the player clicks the menu, the object is created, 200k is used. When they return the object is properly deleted, but the 200k is still in use.
...
(repeat as each time menu is clicked)
I am still looking into the garabage collection suggestion and it more then likely is the answer, just having trouble with that at the moment.
|
|
|
|
|
Since you mentioned garbage collection, I gather you are using .NET. Rather than setting the objects to null or letting them go out of scope, try explicitly callin the Dispose() method as soon as you are done using them.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
It was actually a suggestion by Ryan Binns in the above reply, but only if I was using managed code.
I really am unsure if I am using managed code or not. I read on a website that managed code is code that uses the .NET framework. Well, I don't know if I am, but I know I'm using vs.net 2005, so doesn't that mean I am? How annoying it all is... heh
I read tutorials on sites about garbage collection which state that I am required to include certain dlls and set my Common Language Runtime (CLR). Well, I wasn't using any CLR support so now I am questoning if I really am using managed code. When I set CLR support on, I get numerous errors.
Here is essentially how I've been removing my class objects (the code doesn't sit next to each other, but I've placed them in the order they run...(and they do run)). No memory leaks were detected with my software either (see original post).
class gameplayscene
{
public:
gameplayscene() {miniScene = 0; }
~gameplayscene();
...
private:
...
int miniScene;
menu * mainMenu;
};
class menu
{
public:
menu();
~menu(); //deletes the textures I dynamically loaded.
...
private:
...
};
//User clicks menu button
if (miniScene != 1)
{
mainMenu = new menu;
miniScene = 1;
}
//User Interact with menu and we also draw it to screen
...(do menu stuff here)...
//User clicks return on menu
delete mainMenu;
mainMenu = NULL;
miniScene = 0;
(keep in mind the code was retyped, not a direct copy, and the menu can be called anytime miniScene = 0)
-- modified at 2:17 Tuesday 14th March, 2006
|
|
|
|
|
I'm thinking resource leak.
You might also want to delete mainMenu in the gameplayscene destructor, but if your tools aren't saying there's a leak...
I'm out of ideas. Once you fix it, it will probably either be something blatantly obvious in hindsight or something that will keep you scratching your head every time you think about it (been there too many times.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
what dll or lib coresponding to the sdk? for example mfc lib is supplied in mfc42.lib or mfc42.dll.
|
|
|
|
|
When i run my project on debug mode, i get a message saying that profuis225md.dll is not a valid windows image. If I run it on release mode, the project is ok. I can't debug the project because of this. What can I do to solve this problem. Thanks in advance.
|
|
|
|
|
Hi all.
I want close my form (CFormView dialog) when i press the Esc key.
Please give some code.
Thanks
|
|
|
|
|
pjmvn wrote: I want close my form (CFormView dialog)...
What is a "CFormView dialog?"
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
See this code:
try<br />
{<br />
conn = new CDaoDatabase(); <br />
conn->Open(fileName);<br />
}<br />
catch(CDaoException* error){}
This code will open the Database for me but i can not catch the CDaoException when error. Ex: when the fileName is wrong.
Please help me for this problem.
Thanks
|
|
|
|
|
Hi pjmvn,
try
{
CDaoDatabase *conn;
LPCTSTR fileName="c:\1";
conn = new CDaoDatabase();
conn->Open(fileName);
}
catch(CDaoException* error)
{
switch( )
{
case 1://Here is error code 1 is example
break;
}
}
-- modified at 23:32 Monday 13th March, 2006
|
|
|
|
|
Sorry, my question is not abvious.
This is my code:
try<br />
{<br />
conn = new CDaoDatabase(); <br />
conn->Open(fileName);<br />
}<br />
catch(CDaoException* error)<br />
{<br />
delete conn;<br />
conn = NULL;<br />
LPTSTR errors = L"";<br />
error->GetErrorMessage(errors,100,NULL);<br />
AfxMessageBox(errors);<br />
}
When fileName is wrong. The program does not show Message.
It debug only
|
|
|
|
|
I put a breakpoint at a location and was trying to debug the program. When i hit "run" it should stop at the breakpoint. But, it is giving me a message that "the code has exited" without stopping at the breakpoint. I tried changing the location. Wherever in the program i put a breakpoint and try to debug, the same thing is happening. What might be the problem?
|
|
|
|
|
Sound like the breakpoint isn't being hit. Put a call the MessageBox in the code to verify this suspicion.
Steve
|
|
|
|
|
cuteee wrote: When i hit "run"...
Is this via F5 or Ctrl+F5?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
|
So even though the breakpoint is not being hit, does the code in that routine execute?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi,
I am wondering what the correct way is to properly end a modeless dialog during the OnInitDialog. I currently have 2 (lets call them A and B) dialogs, B is called during the OnInitDialog handling of A. If the return from B is false, then I don't want to display A. When the dialog was modal, I just used an EndDialog(IDABORT) call without any problems. Now that I moved to modeless, I'm wondering if this is still correct. I can't seem to find anywhere that this topic is discussed. Thanks for the help.
Doug
|
|
|
|
|
|
Mike,
This doesn't seem correct since the dialog hasn't been created yet. I agree that typically you use the DestroyWindow() function to close the dialog, but I have created the dialog yet through the OnInitDialog().
Thanks,
Doug
|
|
|
|