处理图片内存溢出问题
1.第一次分析,没有主动del图片对象 ,对应分析表中左图
python">@profile
def my_function(): i = 0for img in line_img_list:i+=1print(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:continueimg_stream = cv2.imencode('.jpg', cv_image)[1] # 编码图片image_obj = BytesIO(img_stream)
1.第二次分析,主动del图片对象 ,对应分析结果右图
python">@profile
def my_function(): i = 0for img in line_img_list:i+=1print(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:continueimg_stream = cv2.imencode('.jpg', cv_image)[1] # 编码图片image_obj = BytesIO(img_stream)del image_objdel img_streamdel cv_image