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
  
相关推荐
夜雪一千3 小时前
Python enumerate() 函数完整详解:遍历同时获取索引,告别手动计数
服务器·windows·python
能有时光4 小时前
PyTorch KernelAgent 源码解读 ---(4)--- ExtractorAgent
人工智能·pytorch·python
_Jimmy_4 小时前
Python 协程库如何使用以及有哪些使用场景
python
aqi005 小时前
15天学会AI应用开发(十七)使用LangGraph实现会话记忆功能
人工智能·python·大模型·ai编程·ai应用
第一程序员5 小时前
Rust Agent 子进程执行:Command 之前,先定义输入和超时
python·rust·github
skywalk81635 小时前
设计并实现段言的 C FFI 绑定机制 @Trae
c语言·开发语言·python·编程
weixin_BYSJ19876 小时前
SpringBoot + MySQL 乒乓球运动员信息管理系统项目实战--附源码04954
java·javascript·spring boot·python·django·flask·php
delishcomcn6 小时前
智切未来:AI算法如何重塑不干胶标签分切机的精度与效率边界
人工智能·神经网络·计算机视觉
EQUINOX17 小时前
【论文阅读】| MoCo精读
论文阅读·人工智能·python·深度学习·机器学习
用户8356290780518 小时前
使用 Python 自动化 Excel 公式和函数:完整指南
后端·python