GUI building and memory usage
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Thomas Koelen
2015 年 5 月 8 日
編集済み: Thomas Koelen
2015 年 5 月 8 日
This is exactly why you stay away from globals...
Use the save and the load function instead!
Matt Fig summarizes it pretty well in one of his posts:
Globals not good: Experience! In my work I help others with MATLAB. Beginners dive right in to globals because they think using them is easy. They are also easy to do wrong. Too often in my work I have to trace through all a user's M-files that use globals, and the base workspace, to find where the user accidentally made a change that is bugging up a entire complicated project. Each function has its own workspace for a reason(s) - and easy bug tracking is one. I always end up teaching people to program by careful data management rather than relying on globals. Usually they have less problems after that with "Where the @#$#*@ is the bug!"
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!