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.