可以使用Python内置的memory_profiler模块来查看python程序的内存占用情况。具体步骤如下:

  1. 安装memory_profiler模块

可以使用pip命令来安装memory_profiler模块:

pip install memory_profiler
  1. 在需要监测内存占用的python程序文件中,添加@profile装饰器
@profile
def my_function():
    # your code here
  1. 使用命令行运行python程序,并加上-m参数和memory_profiler模块的名字
python -m memory_profiler my_program.py
  1. 运行后,会输出程序每行代码所占用的内存情况,可以根据输出结果来查看代码中哪些部分占用了大量内存。

参考资料:[Python学习笔记:如何查看Python程序占用内存](https://www.cnblogs.com/DswCnblog/p/10061885.html

如何查看python程序为什么占用内存大

原文地址: https://www.cveoy.top/t/topic/gsON 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录