xxxxxxxxxx
import os, psutil; print(psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2)
xxxxxxxxxx
import os, psutil
process = psutil.Process(os.getpid())
print(process.memory_info().rss) # in bytes
xxxxxxxxxx
import sys
a, b, c,d = "abcde" ,"xy", 2, 15.06
print(sys.getsizeof(a))
print(sys.getsizeof(b))
print(sys.getsizeof(c))
print(sys.getsizeof(d))
#Running the above code gives us the following result
38
35
24
24
xxxxxxxxxx
import psutil
process = psutil.Process()
memory_usage_start = process.memory_info().rss
print(f"Memory usage at the start: {memory_usage_start} bytes")
# my code
memory_usage_end = process.memory_info().rss
print(f"Memory usage at the end: {memory_usage_end} bytes")
print(f"Memory consumption difference: {memory_usage_end - memory_usage_start} bytes")
image.mefiz.com
https://github.com/MominIqbal-1234
xxxxxxxxxx
Python Garbage Collector interface (gc) will help you with that.
See the link below