Matlab is holding on to a lot of memory. Is this expected?

조회 수: 90 (최근 30일)
Dmitry Kaplan
Dmitry Kaplan 2022년 7월 25일
편집: Dmitry Kaplan 2025년 4월 11일
When I first start matlab2022a, here's my RAM
Matlab is using 4.5G. A lot, but not insane now-a-days.
Here's what happens when I run it for a while -- about 8 hours straight.
Notice that even after the "clear all", matlab is still using >20G.
I think this is having a deliterious effect on the performance of the editor, but I have no proof what-so-ever.
I don't think that clear classes makes a difference. fwiw, I'm not using any. This is purely a number-crunching program: read a file, do complicated stuff, write another file. Nothing fancy.
I am not using HUGE arrays -- about 8G total. Not 20G for sure.
There are no figures displayed. There is no UI. I did run the appdesigner, but closed it hours ago.
I am not using parfors or anything from the parallel computing toolbox (not yet).
Does anyone else see this and perhance found a reason?
I do not believe this happens with 2021a (the only version I have running in addition to 2022a), and I admit that I have never checked this before.

채택된 답변

Chunru
Chunru 2022년 7월 25일
Yes. It seems that your memory usage is "typical" (similar to mine).
MATLAB itself takes up memory, in addtion to variables. For example, the functions and classes it called recently may be stored in the memory. Even after clear all, class definitins used recently may be still in memory.
In addition, it may also depends on how much physical memory you have. If you have large physical memory (it looks so for your system), the OS is perhaps more willing to allocate more memory for MATLAB, especially when other processes have smaller demands.
  댓글 수: 1
Dmitry Kaplan
Dmitry Kaplan 2022년 7월 25일
I will certainly accept the answer. But 2021a doesn't do this :-) weird. I'll keep watching it.

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

추가 답변 (1개)

David Garrison
David Garrison 2022년 7월 27일
There are a couple of things you might try. The inmem function will tell you what functions, MEX files, and classes are currently loaded. That might give you some insight into what MATLAB is using memory for. The toolboxes shown above as well as App Designer all load classes into memory. If inmem shows a lot of things loaded in memory, clear all will not remove them. You have to use clear classes to get rid of them.
Regarding the performance of the Editor, I'm not sure what is happening there. It could be that tab completion is using the in-memory list of functions and classes to search for the right completion so that might could cause a slow down in the Editor.
  댓글 수: 3
Andy Reynolds
Andy Reynolds 2025년 4월 10일
I'm seeing this issue a lot more now that I am designing apps and defining a lot of classes. After running UI apps, then closing them and clearing the workspace, I still have over 45GB RAM in use (R2024b on Linux). Clear classes only frees up about 5GB even when there were over 2000 functions in memory. The only way to free up the remaining 40GB is to restart MATLAB.
Dmitry Kaplan
Dmitry Kaplan 2025년 4월 11일
편집: Dmitry Kaplan 2025년 4월 11일
I have become convinced that, in my case at least, it's an editor bug. I can be typing along and suddenly I lose 20G, then another 20G. I have a lot of ram (256g), but matlab also becomes so slow that I feel like I'm using a 300baud modem. I have reported this a few times, especially when they are trying to have me re-up for another year :-). matlab reports using 5G, but the memory footprint in the process manager is close to 45G. Classic memory leak. I still keep up with the maintenance fees, but I'm basically resigned to using 2021 version and getting better with Python.

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

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by