3

I am having excessive memory usage in my program. In order to debug where exactly memory usage is increasing I am using the below snippet to check the RAM Usage.

memory_usage = sum(sys.getsizeof(i) for i in gc.get_objects())
print('Memory usage in MB', float(usage)/1000000)

Is this the right way to find how much MB of memory is getting used by the Python program? If not can you suggest best way to monitor the memory usage? I also tried

1. resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
2. from guppy import hpy
   h = hpy()
   print "heapsize: ", h.heap()
3.import psutil
  print "Mem usage:",psutil.virtual_memory()

but all of them give very very different results thereby increasing the confusion.

Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
khangaroth
  • 75
  • 3
  • 13
  • duplicate question of: http://stackoverflow.com/questions/938733/total-memory-used-by-python-process – gregory Feb 06 '17 at 06:56
  • 4
    Possible duplicate of [Total memory used by Python process?](http://stackoverflow.com/questions/938733/total-memory-used-by-python-process) – xmcp Feb 06 '17 at 06:59
  • I included the solution recommended but that doesn't help – khangaroth Feb 06 '17 at 07:01

0 Answers0