Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows Win32 MFC memory
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 19-Aug-12 7:51am
Comments
Wes Aday at 19-Aug-12 13:59pm
   
The reason is very simple. Task manager lies. If you want a real answer, conduct an actual test.
Pravinda Amarathunge at 19-Aug-12 14:42pm
   
how do i supposed to do that ?
Wes Aday at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 330
1 Richard Deeming 240
2 Nirav Prabtani 212
3 CHill60 170
4 _Amy 165
0 OriginalGriff 8,104
1 Sergey Alexandrovich Kryukov 7,045
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100