GUI building and memory usage

조회 수: 3(최근 30일)
David Rising
David Rising 2015년 5월 8일
답변: Malcolm Lidierth 2017년 1월 2일
This is maybe a two part question, one specific to my program and one general to gui programming. Specifically, I have a close function for my main gui figure which saves some values stored inside the global structure to a mat file. To actually close the figure and clear the global variable, I added:
delete(1000); %the figure number
clearvars -global s
to the end of my close_func. This doesn't seem to completely free up all of the memory however as I can see the amount of memory that matlab uses increases when I open and close the gui multiple times. Unless there is something going on in Matlab independent of my program which is causing this.
In addition, if I open the program enough times, I eventually get a bunch of java exceptions and the program no longer works correctly. I then have to close Matlab and restart the program. I am assuming that these issues are related. I have discovered in the matlab help an entry about not using the get and set commands with Java objects as this will cause a memory leak. Is this also the case for normal uicontrol/uipanel etc gui objects? Am I correct when I say that they are also Java based?
Thanks and sorry for the possibly ignorant questions but software programming is not my strong suit. Although it is a lot of fun!
  댓글 수: 2
David Rising
David Rising 2015년 5월 8일
I had also read this when I first started to develop the program a while back but couldn't get the callbacks to function correctly for some reason. At the moment the basic program works like so:
global s
then I have a series of what I call "build functions" which do not have the global s declaration but rather read s as an input, modify the figure by adding controls plots etc, then put the modified s back out again. However the call backs all have the global s definition at the beginning because I couldn't get them to work with:
and use varargin in the input for the callback. That is s=varargin{3} (I think it was three, can't remember at the moment).
Maybe worth noting that the intial program start is a function and not a script. Not sure what I am doing wrong here though...

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


Malcolm Lidierth
Malcolm Lidierth 2017년 1월 2일
If you can, re-use figures rather than deleting them.



Community Treasure Hunt

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

Start Hunting!

Translated by