Why is my code not returning the memory to computer?

I am trying to use the ipcam package to capture and process some images and record them on disk continuously, but after each loop the program is just consuming more and more memory and I can't make the matlab return it to the system. I already tried to stop it and use the command pack and all the possible variants of clear, nothing returns the memory to the system. The problem can be replicate with this code:
url = 'http://172.18.131.248/axis-cgi/mjpg/video.cgi';
cam = ipcam(url);
img = zeros(1280, 720, 3);
while(true)
file_name = strcat(datestr(now,30), '.avi');
outputVideo = VideoWriter(fullfile('./', file_name));
outputVideo.FrameRate = 15;
open(outputVideo);
img = rgb2gray(uint8(snapshot(cam)));
for offset = 0:450
writeVideo(outputVideo, img);
end
close(outputVideo);
clear outputVideo;
end

1 Comment

Bruno - please explain why you have a loop that writes the same image 451 times
for offset = 0:450
writeVideo(outputVideo, img);
end
What is the purpose of this code especially since the offset variable is not being used?

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange

Asked:

on 23 Nov 2016

Commented:

on 23 Nov 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!