Close script kept in memory
4 views (last 30 days)
Show older comments
Hi everyone,
I have some trouble with a code called from task scheduler every 20 minutes. Each time, I call a master script which call others ones. Each chil script is also calling a script which is renamed during the process.
I used the exit or quit force function in the master script (and exit in the task scheduler). But, script are kept in memory which is quickly a problem due to the frequency of the process.
Did someone meet this problem ? Have you got any suggestions?
Thank you very much for your help, I will appreciate to answer to your comments,
PS : In the attachment, a quick diagram of the architecture.
Problem closed but not similar : https://fr.mathworks.com/matlabcentral/answers/16933-quit-doesn-t-close-the-program-process-still-running-in-task-manager or

0 Comments
Answers (3)
Jan
on 28 May 2019
What exactly does "code called from task scheduler" mean? How do you call the Matlab code? How do you define "exit in the task scheduler"? "Each chil script is also calling a script which is renamed during the process" - this sounds like a bad programming style. Creating code dynamically has some disadvantages. It is cleaner to keep the code fixed and trigger modifications by providing different inputs. I would not even use a Matlab script for productive work, but I work with functions in general.
I do not know, what causes the observed effect. But I'm scared if I see scripts in different "levels", which are renamed dynamically.
Why do you assume, that the script is kept in memory? It looks like the Matlab instance is not closed. Is there any reason to start a new session at all? What about keeping one session open and using a timer to trigger the repeated calls?
The screenshot is hard to read - is this Matlab 2014a? The taskmanager looks like Windows 10. Matlab 2014a is certified for Windows up to 8.1 only. Maybe an upgrade is the reliable way.
0 Comments
Raphaël Leclercq
on 29 May 2019
1 Comment
Steven Lord
on 29 May 2019
A task is planified to launch matlab with a specific code in arguments every 20 minutes (cf code example).
Would it make sense to have the same session of MATLAB run the code periodically using a timer object, to avoid the cost of starting and stopping MATLAB repeatedly?
"two scripts could call the same child script at the same time."
Can you say more about this? What's special about the script that it can't be run by two separate MATLAB sessions simultaneously? I've done this if not frequently at least sometimes to compare the results of operations in two separate versions of MATLAB when trying to diagnose a problem. [If the answer is what I suspect, that may answer your question "Why functions are better than scripts ?" at least in part.]
Why functions are better than scripts ?
This documentation page briefly discusses one of the key differences that (again, if my suspicion about your workflow is correct) may be very useful for you. Functions can accept input arguments, allowing you to run the same code on different data without changing the code. Scripts cannot accept input arguments.
We don't know which script is in memory but at least one by watching in the Windows command (tasklit).
How long does this task take to run? Does it take close to (or over) 20 minutes to run?
Raphaël Leclercq
on 29 May 2019
2 Comments
Guillaume
on 29 May 2019
Please use 'Comment on this Answer' instead of starting a new answer each time you want to comment. The more answers a question has, the less likely people (or at least I) will look at it since at least one of the answer must be correct. Your question now shows as having been answered 3 times but in fact 2 of these answers are your comments to the only answer.
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!