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?
Asked
Active
Viewed 314 times
0
-
Can you show us the code? – Ander Biguri Mar 22 '16 at 09:07
-
You might want to read [this Q&A](http://stackoverflow.com/questions/13102654/how-should-i-update-the-data-of-a-plot-in-matlab). – Dev-iL Mar 22 '16 at 13:02
1 Answers
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
-
Thank you! I just clf before next imshow function, and problem is fixed! – Jingheng Luo Mar 22 '16 at 13:10
-
@JinghengLuo consider accepting the asnwer as valid if it helped you! (small tick nest to the upp/down arrows) – Ander Biguri Mar 22 '16 at 13:15