2

I'm profiling my Python program, I'd like to know how much memory it's using and if there's any way I can clear it out, I notice that it's using a lot of rss memory, the way I do the profiling is this:

p = psutil.Process(os.getpid())
print p.get_memory_info()

I noticed that the rss memory used increases dramatically after I call a few functions, and I'd like to delete the variables after I'm done. How can I do so that rss memory clears out? But if I do:

p = psutil.Process(os.getpid())
print p.get_memory_info()
ll = []
ll.append(ll)
print p.get_memory_info()

There is no memory allocated in rss.

What exactly gets put in the rss? And any way I can clear it out? Is it safe to do so?

Kirsteins
  • 27,065
  • 8
  • 76
  • 78
Marc
  • 542
  • 8
  • 14

1 Answers1

1

According to psutil docs, rss refers to different value depending on your OS:

Return a tuple representing RSS (Resident Set Size) and VMS (Virtual Memory Size) in bytes. On UNIX rss and vms are the same values shown by ps. On Windows rss and vms refer to “Mem Usage” and “VM Size” columns of taskmgr.exe.

Assuming you are on Linux, RSS (from What you can find out about the memory usage of your Linux programs):

a process's RSS is just how many page table entries in its virtual memory areas point to real RAM (...) Your process's RSS increases every time it looks at a new piece of memory (and thereby establishes a page table entry for it).

You can instrument Python interpreter to run garbage collection.

Check this SO post answers and this FAQ entry for more details.

Community
  • 1
  • 1
Maciej Lach
  • 1,622
  • 3
  • 20
  • 27