Sign in to follow this  

available memory for memory leaks detection

This topic is 4514 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

I had this nice idea to detect memory leaks: 1) at the begining of the program first thing i do is log how much memory is available. 2) at the end of the program (after all the memory has been released) i check again how much memory is available and compare it. If there is less memory than before a memory leak is detected. i wasnt sure if this will work (since maybe other processes can take memory and maybe heap memory can change), but unfortunatly i wasnt able to test it since i couldnt find a "memoryAvailable" function. seemed to me like it should be part of the language (like malloc and free) but i will settle for a WIN32 API function, yet all my googling came to dead end. (i will even be thankful for a linux function, even though i code for windows) anyone knows if the above memory leaks detection can work? and anyone knows if a "memoryAvailable" function exists? (and if so, where can i find it?) thanks in advance, Iftah.

Share this post


Link to post
Share on other sites
it wouldn't be reliable at all since background processes could allocate memory to, and finding the total amount of 'available' memory is a bit hard on modern OS's because of how the memory substem (including virtual memory) works.

For a really crude check in C++ you could simply instrument global operator new and delete to keep track of how much memory was allocated and freed.

Else there's debug heap functions in the Win32 API and [google] can bring up some nice memory manager for you to.

Share this post


Link to post
Share on other sites
Type "perfmon" into the run prompt on xp. That is the tool you want to use to monitor for memory leaks. Select 'Add counters', and 'processes', and select your process and 'virtual bytes', 'private bytes', 'handle count' etc...

Otherwise there's Paul Nettle's memory manager.

Share this post


Link to post
Share on other sites

This topic is 4514 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this