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
  
相关推荐
AI蜗牛之家1 小时前
Qwen系列之Qwen3解读:最强开源模型的细节拆解
人工智能·python
殇者知忧1 小时前
【论文笔记】若干矿井粉尘检测算法概述
深度学习·神经网络·算法·随机森林·机器学习·支持向量机·计算机视觉
whyeekkk2 小时前
python打卡第48天
开发语言·python
丁先生qaq4 小时前
热成像实例分割电力设备数据集(3类,838张)
人工智能·计算机视觉·目标跟踪·数据集
Eiceblue4 小时前
Python读取PDF:文本、图片与文档属性
数据库·python·pdf
weixin_527550404 小时前
初级程序员入门指南
javascript·python·算法
程序员的世界你不懂4 小时前
Appium+python自动化(十)- 元素定位
python·appium·自动化
DisonTangor5 小时前
【小红书拥抱开源】小红书开源大规模混合专家模型——dots.llm1
人工智能·计算机视觉·开源·aigc
CryptoPP5 小时前
使用WebSocket实时获取印度股票数据源(无调用次数限制)实战
后端·python·websocket·网络协议·区块链
树叶@5 小时前
Python数据分析7
开发语言·python