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
  
相关推荐
Birdy_x8 小时前
接口自动化项目实战(1):requests请求封装
开发语言·前端·python
我爱学习好爱好爱8 小时前
Ansible 常用模块详解:lineinfile、replace、get_url实战
linux·python·ansible
一轮弯弯的明月9 小时前
Python基础-速通秘籍(下)
开发语言·笔记·python·学习
春日见9 小时前
自驾算法的日常工作?如何提升模型性能?
linux·人工智能·机器学习·计算机视觉·自动驾驶
千寻girling10 小时前
面试官 : “ 说一下 Python 中的常用的 字符串和数组 的 方法有哪些 ? ”
人工智能·后端·python
第一程序员11 小时前
Python基础学习路径:非科班转码者的入门指南
python·github
u01368638211 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
我材不敲代码11 小时前
OpenCV实战:全自动答题卡识别与评分系统
人工智能·opencv·计算机视觉
smchaopiao11 小时前
Python中字典与列表合并的问题与解决方法
开发语言·python
卡尔特斯12 小时前
Ultralytics YOLO26 自动对指定标注文件夹区分标注素材脚本与训练脚本
python·openai