python内存分析

处理图片内存溢出问题

1.第一次分析,没有主动del图片对象 ,对应分析表中左图

python 复制代码
@profile
def my_function():    
    i = 0
    for img in line_img_list:
        i+=1
        print(i)
        img_stream = minio.download_file("line", img)
        if img_stream is None:
            print("有问题的图片:", img)
            continue
        # 格式化数据流
        cv_image = cv2.imdecode(np.frombuffer(img_stream, dtype=np.uint8), -1)
        if cv_image is None:
            continue
        img_stream = cv2.imencode('.jpg', cv_image)[1]  # 编码图片
        image_obj = BytesIO(img_stream)
  

1.第二次分析,主动del图片对象 ,对应分析结果右图

python 复制代码
@profile
def my_function():    
    i = 0
    for img in line_img_list:
        i+=1
        print(i)
        img_stream = minio.download_file("line", img)
        if img_stream is None:
            print("有问题的图片:", img)
            continue
        # 格式化数据流
        cv_image = cv2.imdecode(np.frombuffer(img_stream, dtype=np.uint8), -1)
        if cv_image is None:
            continue
        img_stream = cv2.imencode('.jpg', cv_image)[1]  # 编码图片
        image_obj = BytesIO(img_stream)
        del image_obj
        del img_stream
        del cv_image
  
相关推荐
dulu~dulu2 小时前
算法---寻找和为K的子数组
笔记·python·算法·leetcode
编程之升级打怪2 小时前
用Python语言实现简单的Redis缓冲数据库驱动库
redis·python
电商API&Tina3 小时前
电商数据采集API接口||合规优先、稳定高效、数据精准
java·javascript·数据库·python·json
玲娜贝儿--努力学习买大鸡腿版3 小时前
hot 100 刷题记录(1)
数据结构·python·算法
兮℡檬,3 小时前
答题卡识别判卷
开发语言·python·计算机视觉
Techblog of HaoWANG3 小时前
目标检测与跟踪(12)-- Jetson Xavier NX / Orin NX ROS及视觉检测环境配置、移植、部署指南
人工智能·目标检测·计算机视觉·机器人·视觉检测·控制
阆遤3 小时前
利用TRAE对nanobot进行安全分析并优化
python·安全·ai·trae·nanobot
雕刻刀4 小时前
ERROR: Failed to build ‘natten‘ when getting requirements to build wheel
开发语言·python
何双新4 小时前
Odoo 技术演进全解析:从 Widget 到 Owl,从 Old API 到声明式 ORM
python
山川行4 小时前
关于《项目C语言》专栏的总结
c语言·开发语言·数据结构·vscode·python·算法·visual studio code