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
  
相关推荐
databook9 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室9 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三10 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271114 小时前
Python之语言特点
python
刘立军14 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机18 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机19 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i20 小时前
django中的FBV 和 CBV
python·django
c8i20 小时前
python中的闭包和装饰器
python
这里有鱼汤1 天前
小白必看:QMT里的miniQMT入门教程
后端·python