Archived

This topic is now archived and is closed to further replies.

freshya

Correct way to release all your memory (DX7)

Recommended Posts

Hello there! Say I have a function that reloads all the graphics in the game. This is called when all the surfaces need to be restored. What the function does is this: for each surface surface->Release(); Create_DDraw_Surface(surface, parameters); LoadBitmap(name); GrabBitmap(surface, bitmap, coords); CloseBitmap(); loop The problem is, that every time it gets called, it takes longer and longer and longer. So for example, the first time you alt-tab, it takes 400 milliseconds to reload everything, but after about 10 more alt-tabs it takes over 4000 !!! And to make matters worse the hard disk starts thrashing, which is most peculiar for my game. Is there an additional step I should take to ensure that all memory is accounted for? Thanks, freshya

Share this post


Link to post
Share on other sites
Did you also release your bitmaps?

If you work with VC you normally have debug output from DX in your panel. It shows on exit which resources have not been released properly. Also take care to free your own resources.

My way to find difficult memory leaks is brute force: put all creation code in coments until no leaks are reported, then bring them back to life until the one is found that caused the leak.

- thomas

Share this post


Link to post
Share on other sites
Could you point me to the ->Restore method in DX8?

Sure, MANAGED resources might not have to be reloaded, but then again, they don''t need to be restored either :p

Seems to me like you''re doing the right thing. I get the "Textures take longer and longer to load" problem in my DX8 engine as well, but only when I use the CRT to track memory leaks.. Maybe you''re using it also? If so, try turning it off.

Orbitalx

Share this post


Link to post
Share on other sites
Thanks guys, I will try your method Renus.

OrbitalX - What is CRT? I have tried running the program outside of VC++ altogether and it still gives the same problem.

Share this post


Link to post
Share on other sites
*Grr* If you need something done right do it yourself =) Well that''s the last time I''m trusting code from André LaMothe ! I know I shouldn''t really have just used his bitmap loader as is but file type protocols aren''t really my scene. It turns out that function was wasting about 1.5mb each time for an 800x600 bitmap! Crikey! Anyway, problem solved =)

Oh, and Tornado - I shut them down completely because the function is used for various things in the game, not just the alt tab effect, and thus it needs to be flexible. The call to release is part of my "global plan" for shutting down sprites (i haven''t posted the entire code here), which involves removing all memory I allocate for my own nefarious needs, etc etc. I shut them down completely because I might want to change image sizes.

Share this post


Link to post
Share on other sites
quote:

Could you point me to the ->Restore method in DX8?



Sure dude, but it seems freshya is talking about DX7, not 8

quote:

OrbitalX - What is CRT? I have tried running the program outside of VC++ altogether and it still gives the same problem.



Here''s how you can use the CRT to detect memory leaks (Very effective): (Remember to include crtdbg.h)

  
// this way, if you run your application in debug, the debugger will let you know of memory leaks

// this isn''t my code btw, saw it a while back at flipcode

#ifndef NDEBUG
int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
flag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(flag);
#endif


quote:

Oh, and Tornado - I shut them down completely because the function is used for various things in the game, not just the alt tab effect, and thus it needs to be flexible. The call to release is part of my "global plan" for shutting down sprites (i haven''t posted the entire code here), which involves removing all memory I allocate for my own nefarious needs, etc etc. I shut them down completely because I might want to change image sizes.



Ok, No problem



- Goblineye Entertainment
The road to success is always under construction

Share this post


Link to post
Share on other sites