Memory Leaks 
Author Message
 Memory Leaks

Is there an API call to get the Memory usage (as we see in Task Manager) ?


Sun, 27 Mar 2005 18:25:55 GMT  
 Memory Leaks

Quote:

> Is there an API call to get the Memory usage (as we see in Task
> Manager) ?

GetProcessMemoryInfo

Normally task manager shows the following value: WorkingSetSize

But this is not the memory usage of an process (this is only the value
which is in physical memory).

If you need the memory of the whole process you should use the
"PagefileUsage" entry.

By the way: The WorkingSetSize can contain 0! (Just execute
SetProcessWorkingSetSize(getCurrentProcess(), -1, -1);)

--
Greetings
  Jochen



Sun, 27 Mar 2005 18:37:07 GMT  
 Memory Leaks

Quote:
> Is there an API call to get the Memory usage (as we see in Task Manager) ?

If you're trying to find/fix memory leaks, take a look at the _CrtDbg.xxx
routines. They work very well for CRT memory usage. Use IMallocSpy to look
for COM leaks.

I recommend you stop using Task Manager, use Perfmon instead. You can view
memory usage on a per-process basis.  Use "Handle Count" to see leaks to do
with HANDLEs. Perfmon says:

"The total number of handles currently open by this process.  This number is
the sum of the handles currently open by each thread in this process."

Use "Private Bytes" to find memory usage on all Heaps (there's more than 1).
perfmon says:

"Private Bytes is the current number of bytes this process has allocated
that cannot be shared with other processes."

I have done experiments in the past where I allocated a block of bytes (4K
at a time) and the only perfmon counter that matched the number of bytes
allocated was "Private Bytes".

Note that Task Manager's "Virtual Memory Size" matches perfmon's "Private
Bytes". Task Manager's "Mem Usage" doesn't correspond to anything as far as
I can tell.



Sun, 27 Mar 2005 23:28:16 GMT  
 Memory Leaks

Quote:


> > Is there an API call to get the Memory usage (as we see in Task Manager)
?

> If you're trying to find/fix memory leaks, take a look at the _CrtDbg.xxx
> routines. They work very well for CRT memory usage. Use IMallocSpy to look
> for COM leaks.

> I recommend you stop using Task Manager, use Perfmon instead. You can view
> memory usage on a per-process basis.  Use "Handle Count" to see leaks to
do
> with HANDLEs. Perfmon says:

All of that information can be displayed in Task Manager as well, on the
"Processes" tab.  Choose View|Select Columns... from the menu to choose
which columns to see.

-cd



Sun, 27 Mar 2005 23:39:17 GMT  
 Memory Leaks


Quote:
> > I recommend you stop using Task Manager, use Perfmon instead. You can
view
> > memory usage on a per-process basis.  Use "Handle Count" to see leaks to
> do
> > with HANDLEs. Perfmon says:

> All of that information can be displayed in Task Manager as well, on the
> "Processes" tab.  Choose View|Select Columns... from the menu to choose
> which columns to see.

You're right they can be. However Task Manager does not indicate what the
displayed values mean. Specifically does "Mem Usage" report virtual memory,
system memory, physical memory, shared memory, working set, pooled or
non-pooled bytes, or a total of all or some of these?

It makes a difference if you're searching for memory leaks. For example, in
my experiments I allocated a 4K block, Private Bytes jumped up by 4K,
Virtual Memory jumped by some other amount and Working Set didn't change at
all... or it did but not necessarily by 4K.

Also Task Manager is misleading with regards to it's labelling "Virtual
Memory Size". It may be misleading about other counters. The numbers
displayed by Task Manager and Perfmon are all derived from NT's performance
counters so the values will match up somehow, the question *is* how?

Just my .02, which when looked at from the perspective of "free" advice is
way overpriced.



Mon, 28 Mar 2005 00:06:22 GMT  
 Memory Leaks

Quote:
> > All of that information can be displayed in Task Manager as well, on the
> > "Processes" tab.  Choose View|Select Columns... from the menu to choose
> > which columns to see.

> You're right they can be. However Task Manager does not indicate what the
> displayed values mean. Specifically does "Mem Usage" report virtual
memory,
> system memory, physical memory, shared memory, working set, pooled or
> non-pooled bytes, or a total of all or some of these?

[snip]

> Also Task Manager is misleading with regards to it's labelling "Virtual
> Memory Size". It may be misleading about other counters. The numbers
> displayed by Task Manager and Perfmon are all derived from NT's
performance
> counters so the values will match up somehow, the question *is* how?

Yep.  It's all true - at least with Perfmon you know what you're getting,
since it displays only raw counters properly labelled.  I only wanted to
point out (what apparently many people don't know) that Task Manager can
display much more than it would first appear.

-cd



Mon, 28 Mar 2005 00:16:47 GMT  
 Memory Leaks

Quote:
> Yep.  It's all true - at least with Perfmon you know what you're getting,
> since it displays only raw counters properly labelled.  I only wanted to
> point out (what apparently many people don't know) that Task Manager can
> display much more than it would first appear.

Agreed TM is a useful little ditty.


Mon, 28 Mar 2005 00:36:43 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Handle leak, memory leak...

2. Class object, returning pointers, dynamic memory, memory leaks

3. Finding memory leaks in shared memory pool

4. Memory leaks, DLL and memory allocation.

5. Tracking memory leaks and debugging memory problems

6. Memory leak when using Memory DC

7. About memory leak in VC++, how can i know where my program has memory leak?

8. Tracking down memory leak?

9. Interop memory leak with VB.NET to VC++

10. MDI splitter child crame and memory leaks

11. Memory leaks

12. memory leak with BSTR or VARIANT or other web browser MSHTML interfacing

 

 
Powered by phpBB® Forum Software