Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I know some programming (C/C++, JAVA, Win32..), but I don't know advanced concepts of Computer Science. I just know the basics. This question is about memory management in Windows Operating Systems. You can see the problem by just observing.

1. Open a file using Notepad by double clicking a file.
2. Open the Task Manager, and under processes tab you'll find the memory taken by the Notepad.exe (it is about 1,400 K)
3. Then open a file using the Common Dialog Boxes Library which is used in Notepad (Goto File --> Open).
4. Now you'll see the memory taken by Notepad.exe in the Task Manager as about 8,000 K.

Why is that ? And Even After when closing the Open File Dialog, the memory will not change. Why isn't Windows (or the library or anything else) freeing the memory after closing the Open File Dialog.


Need a good Answer !

[I'm using Win7 64bit)
Posted
Comments
[no name] 19-Aug-12 13:59pm    
The reason is very simple. Task manager lies. If you want a real answer, conduct an actual test.
Captain Price 19-Aug-12 14:42pm    
how do i supposed to do that ?
[no name] 19-Aug-12 15:45pm    
You are developer, write a program. If you want to see how much memory object take up then use a profiler.
Sergey Alexandrovich Kryukov 20-Aug-12 1:49am    
Very correct but perhaps not very informative... :-)
Would you take a look at my answer where I give a bit more precise advice on how to "write a program" properly?
--SA

As Wes said, the task manager is telling you how much RAM the process has allocated to it for use, not how much it is using. It is good for a vague idea, or to show a runaway process, but it's not accurate at the granularity you're wanting it to be.
 
Share this answer
 
I can give you a more specific idea if you have problems with memory allocation, such as memory leak, of not-enough-memory problems. The type of product you need is called "memory debugger".

You can find the one suitable for you from this list:
http://en.wikipedia.org/wiki/Memory_debugger#List_of_memory_debugging_tools[^].

At least some of these products are open-source.

Another (but not alternative, it could be the additional) approach is the validating library which you can use during run-time. Such library intercepts/replaces C++ memory allocation operations and count the balance. It can pinpoint the object where the memory is not completely released. Unfortunately, I cannot point you a particular 3rd-party library which you can use with contemporary C++ compilers, but if you use Visual Studio, you can use its debugger along with CRT libraries to detect and pinpoint memory leaks. Please see:
http://msdn.microsoft.com/en-us/library/x98tx3cf%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx[^].

You can improve your memory handling experience and reduce amount of manual work if you use some more advanced techniques like automatic pointers, which provide limited garbage collection facility for pointers:
http://www.cplusplus.com/reference/std/memory/auto_ptr/[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900