- On the Home tab, in the Environment section, click Preferences. Select MATLAB > General > Java Heap Memory.
- Select a value using the slider or spin box.
Memory usage limitation for standalone Matlab app designer Apps using Matlab Compiler
12 views (last 30 days)
Show older comments
Hi all,
I have a simple question which need a simple answer (i hope i will not hear the can't be done answer as i am expecting it):
i am making an app in matlab App designer and then converting it to EXE file to run on client computer. the problem as as above i need somehow to dynamiclly control the memory usage of my EXE app according to available physical memory of my client. can i do this?
my goal is to simply limit the available memory to my Matlab EXE app to lets say 80% client system physical memory. is it possible?
I have already tried the Matlab Workspace in Preferences option and did not work for me. (the code is too big to change now, and that is why i dont want to change the code if possible. my bottleneck is FFT calculation on a matrix of about /this may change/ 3000000x6 which as you can see i know but i dont if possible want to change)
Thanks for the support
Best Regards
0 Comments
Answers (1)
Harsh Mahalwar
on 19 Feb 2024
Edited: Harsh Mahalwar
on 19 Feb 2024
Hi Aubai,
As I can understand, you are trying to limit MATLAB’s memory usage according to the available memory. Using MATLAB workspace in preference option is a possible solution but you have already tried that, and it did not work for you.
Here’s a workaround, you can also try changing the java heap size.
To adjust the heap size:
Note: Increasing the heap size decreases the amount of memory available for storing data in arrays.
3. Click OK.
4. Restart MATLAB.
But obviously, I can understand that changing Java heap size might not be a good solution in your use case as it is not possible to adjust the heap size dynamically (at least effectively, there are ways to change it with code, but they require a restart).
Another possible workaround can be to use the “memory” function with a break loop. Here’s an example:
% for this example, I am setting memory threshold as 80
thresholdMemory = 80;
while true
% You can call your entry point function here!
% This part checks memory usage.
[~, memObj] = memory;
availableMemory = memObj.PhysicalMemory.Available;
totalMemory = memObj.PhysicalMemory.Total;
memoryInUse = 100*(totalMemory-availableMemory)/totalMemory;
% break loop if memory usage exceeds the threshold.
if memoryInUse > thresholdMemory
break;
end
end
Learn more about the “memory” function using the following link:
I was also able to find a similar MATLAB Answers question, you can also try using methods suggested here,
You can also try using Operating system specific memory management methods like,
Using Windows job object, this is a bit advanced and requires programming with the Windows API. You can also leverage third party applications for the same.
(this method is not supported by MATLAB officially, so it might be more tedious to work with)
In case of linux, you can use the ulimit command in the shell to limit the resources available. “cgroups” feature can also be used. (you can checkout open-source job schedulers like “slurm workload manager”).
(this method is not supported by MATLAB officially, so it might be more tedious to work with)
I hope this helps, thanks!
3 Comments
Harsh Mahalwar
on 20 Feb 2024
Edited: Harsh Mahalwar
on 20 Feb 2024
Hey Aubai,
You're correct here, memory function can only be used to display information related to memory usage. I'll remove my comment.
See Also
Categories
Find more on Develop Apps Using App Designer 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!