close and restart matlab ? or another way out?
204 次查看(过去 30 天)
显示 更早的评论
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
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
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
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.
0 个评论
Jeno Boka
2022-4-12
Try this handy script: Restart MATLAB - File Exchange - MATLAB Central (mathworks.com)
You can also add it to your favorites
1 个评论
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!