Your function my_function()
creates a list with 1.000.000 integers, which will take up a significant amount of memory and the difference in memory it's because different memory profiling libraries use different methods to measure memory usage
memory_profiler
uses a line-by-line memory profiler that calculates the memory usage of each line of code.
tracemalloc
uses a lower-level approach to measure memory usage. It tracks memory allocations and deallocations directly from the Python interpreter, which can result in lower reported memory usage.
psutil
uses system-level APIs to measure memory usage. It reports the memory usage of the entire process, including both Python objects and other system resources used by the process.