Memory Usage

Peter Hansen peter at engcorp.com
Mon Jan 24 10:55:26 EST 2005


rbt wrote:
> Peter Hansen wrote:
>> I would expect to see such behaviour, given how difficult it is
>> to measure *actual* memory usage.  How are you measuring it?
>> Just by looking at the Mem Usage column in the Task Manager?
> 
> That's right. I look at that column. Should I measue mem usage in some 
> other way?

Probably, but for a start, have you noticed that even just
switching to another window can drastically affect the
memory apparently used by an application?  For example,
running the wxPython demo, clicking on a few controls and
getting memory usage up to 27MB, then minimizing the window
will drop it down aboiut 2MB.  Restoring the window will
bring the amount back to only about 4MB, at least until
you click on stuff.  Even then, it might climb to only
about 14MB or so.

This particular phenomenon might not be affecting your
application, but it's an indication of how bad this
measurement technique can be.

Inside the Control Panel, you will find "Administrative Tools".
In there is a "Performance" gadget.  It's not trivial to
use, and I can't give a tutorial here, but if you can
manage to display the Working Set for the specific Process
in which you are interested, that's probably a better
way to view the information.  (To be honest, I think it's
actually this particular value which the "Mem Usage"
field shows in the Task Manager, but at least this way
you get a real-time graph and more precision, and a
record of the usage.)  There are also dozens of other
parameters you can examine to help you track down the
actual usage, or to help find out what is going if it turns
out that you really are using such different amounts on
the two machines.

More important than any of this, however, might be making
sure you have similar conditions on the two machines.  Are
you terminating as many other processes as you can?  Making
sure there is ample Physical Memory Available (see the
Performance tab of Task Manager, for example)?  If you
have one of the machines running out of memory because
of other applications running, it is quite possible that
the OS will steal memory from the Python process to feed
the other apps, and that can show up in the working set size.

As I said, this stuff isn't exactly straightforward, so
it's not necessarily surprising you are seeing this behaviour.
There's probably a relatively simple explanation, however,
but it might come only after a bit of exploration.

-Peter



More information about the Python-list mailing list