Out of Memory for using many global variables
1 view (last 30 days)
Show older comments
Hi
I have many functions. so instead of use the variables as function arguments to transfer values between functions. I set many variables as global variables. These global variables are not used all the time.
on the top of main function, I did use the following to clear the space.
clc clear all; close all; however, when opening a big excel file(200MB), I ran into out of memory issue for 2014b version. When I change it to use 2017 version. the issue was gone but loading speed for opening excel using xlread() is still very slow. Now I need your help on the following questions.
1. How to reduce memory space with many global variables? How to only assign space when it is used? 2. I have few toolboxes, like statistics, which are only linked to 2014b version. Is it possible to use these toolbox for 2017 version?
Thank you so much for your help. I appreciate it.
11 Comments
Walter Roberson
on 9 Feb 2018
If you have enough data to be running out of memory, you should be using setappdata()/getappdata() instead of guidata(). guidata() is invoked by GUIDE for every callback, and a copy of all the stored data is created each time. With setappdata()/getappdata(), you can pull in copies of just the data you need.
Even then, since the data is large, you should probably instead rewrite your code to use nested functions with shared variables -- or create a handle object containing the array, possibly using https://www.mathworks.com/help/matlab/matlab_oop/handle-compatible-classes-and-heterogeneous-arrays.html
Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!