处理图片内存溢出问题
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