I can't find a solution to avoid this crash.
I have cleaned up the attached code because it contains the issue and nothing else.
Regardless of the size of the image, the program crashes after 368 iterations.
I also tried what I could find in the forums but no solution found ( plt.close('all'), gc. collect().... ).
import matplotlib.pyplot as plt
import cv2
compteur = 0
image = cv2.imread(r"D:\OneDrive\Bureau\New folder\12345.jpg")
while True:
print('1')
ax_user = plt.imshow(image)
print('2')
plt.close('all')
print (f'\n{compteur}:\t')
compteur += 1
367:
1
2
368:
1
Fail to allocate bitmap