Archived

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

if memory leaks happens...

This topic is 4960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Nope. You''ll have to do a restart. If you create dynamic memory in C++ and then not release it back to the OS, the OS will forever think you are still using it until you release it explicitly. In other words, if you have a memory leak you''ll have to restart for it to be reclaimed.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That''s true with Win98, but not with Win2K/WinXP. After the process is killed, they''re much better at cleaning up after you (they are modern kernels, not that DOS garbage). That''s not a license to leak memory, but it''s comforting to know that your application won''t steal the systems memory forever and ever.

Share this post


Link to post
Share on other sites
quote:
Original post by Fish HF
it seems wind0ws 9x isn''t that bad at all lol


The problem with the windows 9x memory management, is it''s caching system. It caches a lot of resources, in case they are needed later, usually doing it too much, that there''s no memory left for the program, or that the system gets unstable...

There might also be bugs in the memory cleanup system, but it''s supposed to work at least in teory.

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
Hmm, my college profs always said that 9x is unable to clean up leaked memory. Anyone with Win9x want to see if that''s the case?


He probably said it to make you avoid memory leaks at all cost

Share this post


Link to post
Share on other sites
I used 95 for years, far far too many years. (Years after M$ discontinued support for it in fact) It was quite capable of cleaning up after leaky processes once they exited.

The main issue was that if the leaky app crashed, if often took most of the system with it!

Given how MSVC++ loves to leak, and hose my system in the process, using 95 did involve many restarts.

Finally moved to Win2k though - much, much better.

[edited by - zoggo on May 20, 2004 4:06:24 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by zoggo
I used 95 for years, far far too many years. (Years after M$ discontinued support for it in fact) It was quite capable of cleaning up after leaky processes once they exited.




Win98 will clean up eventually, it is not always immediate. Try it.

for( int i = 0; i < 10000; i++)
{
char * s = malloc(1000);
}

exit(0);

and watch the resource meter in 98. In a while it will return.

Win95 was hodeous stuff, I can not beleive they actually charged people for it to be honest. Actually, I can''t believe people actually bought it. Win98 at least worked better.



Share this post


Link to post
Share on other sites
I''ve definately had problems with win 98 not returning memory. Run windows explorer 10 times in a row and you''ll probably run out of memory. In theory, it should return the memory, but the 95/98/ME versions of windows are notorius for being terrible at memory management. A simple example like the malloc one just posted isn''t a good measuring stick of real life circumstances.

Even if the system does return the memory when your program exits, none of them will return it while you''re still running. So, if you have a routine that leaks memory and you keep calling it, eventually you''ll run out of memory. It''s good practice to not depend on the OS to clean up your dirty work.

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
Hmm, my college profs always said that 9x is unable to clean up leaked memory. Anyone with Win9x want to see if that''s the case?


Depends on what kind of resource, and what kind of quit.

If you "crash" then it might not clean up memory you leaked through certain allocations.

If you shift-F5 ouf of an application in the debugger, it will NOT clean up almost ANY resources (GL contexts, etc).

If you exit the process with an ExitProcess(), most resources will get cleaned up.

I suggest wrapping your code in a __try/__except which posts a dialog box that there''s been an irrecoverable error in the program, and then call ExitProcess(). That way, you DO clean up all the memory, even when crashing.

XP (or other OS-es based on a "real kernel") don''t have this problem, and can clean up all resources as necessary when the program dies. Some subsystems may have bugs in certain versions, though.

Share this post


Link to post
Share on other sites