Memory leak when using preview on an App axes

I did a simple GUI to display my camera in real time. I'm using global variables because I need to get some data of the frames (from another GUI) in order to process them. The code is the following:
global images;
images.camera = videoinput('winvideo',1);
set(images.camera,'ReturnedColorSpace','rgb');
set(images.camera, 'FramesPerTrigger',1);
set(images.camera, 'TriggerRepeat', Inf);
triggerconfig(images.camera, 'manual');
start(images.camera);
cla(app.axes_livecamera, 'reset');
pause(0.2);
img = zeros(480, 720, 3);
images.hImage = imagesc(img, 'Parent', app.axes_livecamera);
pause(0.2);
images.preview = preview(images.camera, images.hImage); %Here is when memory increases
%images.preview = preview(images.camera); %This way memory does not increase.
However, when I start previewing the camera on an axes (instantiated by images.hImages), the memory start increasing until MATLAB crashes (when it consumes around 9GB of RAM). Even though, when I preview my camera in the default figure of preview (withouth instantiating images.hImage), memory does not increase, so I think it might be a problem of axe's handles. How can I avoid this memory leakeage? I need to show my image in app.axes_livecamera, not in the default figure of preview.
Thanks

2 Comments

Hey, I have the same issue. Did you resolve this somehow?
Nope, i think it is a MATLAB bug. With the help of the debugger I realized that the old frames were stored within app children, but i couldn't reset it. The solution was to plot the preview onto a figure and not into the axes.

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Asked:

on 6 Feb 2019

Commented:

on 14 Aug 2020

Community Treasure Hunt

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

Start Hunting!