0

I read a video, but I want to show frame one by one, but when I show the frame, I found my memory leak out, and my program get slow, it shows that imshow() will not free the memory, so can I free the memory after showing the image, but the image never goes out, I can show the image frame by frame as well?

1 Answers1

4

I bet you are doing something like

hold on
for ii=1:frames
    imshow(frame)
    drawnow
end

as most memory problems are due to this structure. If you hold on and never clear the figure, you will draw on top of whatever is there, but it will never get deleted. I suggest you remove the hold on if you are just drawing a single thing inside the loop, and if you are drawing more than one thing inside and you need the hold on, then add cla (clear axes) or clf after the drawnow, or in the begging of the loop.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120