How can I monitor how much memory MATLAB is using?
Afficher commentaires plus anciens
I have a program that is memory intensive and I want to monitor how much memory MATLAB is using so that if it goes above a certain threshold, I can stop the program.
Réponse acceptée
Plus de réponses (1)
Jan
le 4 Mai 2016
Note that "memory usage" is not well defined. When the code let an array grow iteratively, it requests new memory in each iteration:
v = [];
for k = 1:1e6
v(k)= rand;
end
Although the final array uses 8MB only, Matlab requests sum(1:1e6)*8 = 500GB of memory from the OS. Of course Matlab releases the memory, but the OS waits until it finds time to clear the memory and overwrite it with zeros. Therefore even this cute loop can exhaust the RAM. But do you consider the released and not yet cleared RAM as "occupied by Matlab" or not?
If you open a lot of files simultaneously in Matlab, the memory for caching reserved by the OS can grow to a remarkable size. This is caused by Matlab, but the memory does not belong to Matlab in the taskmanager. Matlab can store data on the graphic card also.
If several threads, e.g. in parfor, access data in the same cache-line (usually a 64 byte size block of memory), the total performance can degrade drastically. This could be considered as "memory intensive task" also, although it concerns a tiny memory block only.
In consequence "memory usage" is as vague as "processor time" in modern operating systems.
1 commentaire
Walter Roberson
le 25 Oct 2016
MATLAB keeps a "small block" memory pool and will clean it out as needed. I do not know if it will re-use the same location over and over or if it uses a more round-robin strategy.
Catégories
En savoir plus sur Profile and Improve Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!