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

6 Ansichten (letzte 30 Tage)
Ji Hyun Ko
Ji Hyun Ko am 7 Mär. 2012
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

Akzeptierte Antwort

Titus Edelhofer
Titus Edelhofer am 7 Mär. 2012
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 Kommentare
Titus Edelhofer
Titus Edelhofer am 8 Mär. 2012
Hi Sean,
it's here:
http://www.mathworks.com/help/techdoc/matlab_env/f0-12994.html#f0-38522
Titus
Daniel Shub
Daniel Shub am 8 Mär. 2012
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

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

Daniel Shub
Daniel Shub am 7 Mär. 2012
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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by