quit doesn't quit the matlab when called from a loop.

3 次查看(过去 30 天)
Hello,
I am running a m-script that makes a lot of memory leak, and it reaches 2GB in about 3 hours. Since I am calling a lot of functions that somebody else created, I figured it is easier to just restart the function whenever it reaches memory maximum, and resume the loop. So, I implemented [!matlab -r myMscript] in the loop, but it won't quit so it won't free up the memory.
For example, the following script doesn't quit the matlab.
for i = 1:100,
if mod(i,20)==0,
!matlab -r test=1
quit
end
end
My matlab version is 7.7.0.471, and I have 64bit computer (Windows 7). The matlab is running with 32bit-mode.
Could anybody help me to dissovle this problem?
Best,
Ji Hyun

采纳的回答

Titus Edelhofer
Titus Edelhofer 2012-3-7
Hi,
never thought about this way of doing this. You could try to do the following:
!matlab -r test=1 &
Note the & at the end of the line to not wait for the new instance to close.
Titus
  4 个评论
Titus Edelhofer
Titus Edelhofer 2012-3-8
Hi Sean,
it's here:
http://www.mathworks.com/help/techdoc/matlab_env/f0-12994.html#f0-38522
Titus
Daniel Shub
Daniel Shub 2012-3-8
I am not sure that I like the fact that MATLAB spawns processes that it doesn't kill when you quit. Part of me thinks this is really bad behavior. The background running of a task makes sense, but I think MATLAB should clean up after itself.

请先登录,再进行评论。

更多回答(2 个)

Sean de Wolski
Sean de Wolski 2012-3-7
Interesting idea. when you run:
!matlab
it halts execution in the current MATLAB instance until the new instance closes.

Daniel Shub
Daniel Shub 2012-3-7
I think Sean de gives the reason for your problem. As for a work around, I can think of a bunch of ways and it is really what you are most comfortable with. I think the key is to modify your script/function so that it only does a few loops and then exits. The "hard" part is letting the script figure out what loops to do. You could use the script name, check for an environment variable, pass an argument, etc).
Then you need to call the script/function, wait for it to end, and call the next one. If you have the parallel computing toolbox and/or a cluster, you could use a scheduler. I would probably write a shell script to do it. You could use MATLAB to do it.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by