Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need some pointers on Memory Usage

357 views
Skip to first unread message

Pavel Lebedinsky

unread,
Dec 20, 2002, 4:46:51 PM12/20/02
to
"Pankaj K" wrote:

> I was looking at the "Virtual Bytes" eaten up by 'my application'
> process to get the real footprint of the memory usage. But when I
> look at the task manager and monitor the memory usage
> manually, I see the difference between the values of Performance
> Counter "Virtual Bytes" and "Memory Usage".

Here's the mapping from perfmon terms to Task Manager terms:

Working Set -> Mem Usage
Private Bytes -> VM Size
Virtual Bytes -> N/A

For your purposes, you need to be looking at Private Bytes.

> I have following two interpretations of the same -
>
> 1. What Task Manager shows as memory usage is not the real
> memory usage, but is the amount of the memory used by the
> application from the main memory (RAM). So essentially it is
> memory footprint of the Application in _main memory_, not
> overall.

As I mentioned above, Mem Usage is really Working Set, so this
is more or less correct.

> 2. Virtual bytes should be (total code size+ data size) for my
> application, and should be the correct measure.

This is incorrect. Virtual Bytes include both reserved and
committed pages. The only thing this counter tells you is how
close you are to the 2GB limit (on x86, without /3GB switch etc).

Code+data is best approximated by Private Bytes, but you need
to understand that this does not include pages shared between
processes, such as most DLLs and memory mapped files.

> I also want to know that, if my Virtual Bytes usage is constant
> over a period of time, but main memory usage is continusouly
> increasing, say because of some pages are cached, and retained
> in main memory (pinned) to avoid swapping by OS, and are not
> swapped out. So in such a condition is my application leaking
> memory? Or after some time, I am gonna expereince thrashing?

Take a look at your private bytes. You could be leaking heap
memory, in which case there will be steady increase in private
bytes.Virtual Bytes in this case could be stable for some time
(until the heap decides to reserve another segment of virtual
memory, which will look like a sudden jump in Virtual Bytes).

> What exactly should be a measure for deciding a memory leak?

Well, it depends on what kind of memory is leaking. Typical leaks
(forgetting to free() or delete objects) should look like continuously
growing Private Bytes.

Sometimes you can see Virtual Bytes grow while Private Bytes
is stable. This could be caused by a leak (e.g if you reserve some
memory with VirtualAlloc and forget to VirtualFree it) or it could
be something like heap fragmentation.


0 new messages