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

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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

제품

질문:

2019년 2월 6일

댓글:

2020년 8월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by