close and restart matlab ? or another way out?

조회 수: 326 (최근 30일)
AA
AA 2018년 2월 6일
답변: Matthew Johnson 2022년 4월 25일
Hello,
I have a code that is quite computationally and memory-wise intensive and given the RAM(64Gb) I have, I can utilize it for my purpose and get my work done. My code does some kind of optimization, so I need to run my code again, but even after upon performing these operations
clear all;
close all;
pack;
I observe that MATLAB does not release the RAM fully, and only upon restarting, it does. I have some idea that this is a known problem with MATLAB, but I am just curious, has there been any new development that can help? I have R2017a running on Ubuntu16.04
Secondly, I am OK with re-starting and launching a new session, but running these commands
system('matlab &');
exit;
does not help. I see a startup screen, but there is no new window. Also, removing the '&' from above launches a new window but the previous one remains and the RAM is not freed.
Can anyone please help me with this?
  댓글 수: 3
Waddah Moghram
Waddah Moghram 2021년 10월 2일
Having the same problem here. I was wondering when the folks are going to address this problem. So far, I have been shutting down and starting parallel pools, but after a few rounds of doing this, MATLAB becomes so sluggish that you have to close the whole thing and run it again.
Jan
Jan 2021년 10월 2일
@Waddah Moghram: I asked for details in the original quiestion already, because it was not clear. Now you explain, that you have "the same problem". How do you know this?
Please open a new question and explain your problem with details. What does "closing the hole thing" mean?

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

답변 (2개)

Matthew Johnson
Matthew Johnson 2022년 4월 25일
I think the problem with running the commands as OP stated is that it tries to launch the new instance of MATLAB before the old one has quit. This is slightly also undesirable e.g. on the Mac where the first instance you launch is in some sense the "main" instance (e.g. subsequent instances spawn new entries on the Dock but the first one doesn't, at least if you have MATLAB permanently in the Dock as I do).
My somewhat sub-optimal solution has been to put a shell script somewhere, such as my home directory, that launches MATLAB after a few seconds of sleep. For instance mine is called sleepmatlab.bash and it contains this:
#!/bin/bash
sleep 8;
open /Applications/MATLAB_R2020b.app
You can obviously change this for the appropriate MATLAB-launching command on your system and titrate the sleep time so that it is long enough to ensure the typical MATLAB instance fully shuts down without being too much longer.
Then in MATLAB I have another script, restartmatlab.m , that comprises the following:
! ~/sleepmatlab.bash &
exit
So now when you want to restart, run restartmatlab from within MATLAB. It will call the Bash script, which will sleep for 8 seconds, and then exit MATLAB. Presumably in those 8 seconds MATLAB will finish fully shutting down, and then soon after the Bash script will reawaken and open a fresh instance.
If anyone out there is better at shell scripting than I am (or equally good but less lazy), you could probably pretty easily modify this approach so that the shell script checks the ps command every 1 second or so, and launches MATLAB as soon as it is no longer listed among the running processes, instead of sleeping for a fixed duration.

Jeno Boka
Jeno Boka 2022년 4월 12일
You can also add it to your favorites
  댓글 수: 1
Jan
Jan 2022년 4월 12일
The OP explained already, that system('matlab &'); does not solve the problem. Then suggesting a function, which does exactly the same, will not help.

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

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by