The DESTROY command in the Distributed Computing Toolbox removes the job object reference or task object reference from the local session, and removes the object from the job manager memory.
However, when a job is finished, it remains in the job manager even if you clear all the objects from the client session. The job manager keeps all the jobs it has executed until you restart the job manager in a clean state.
Additionally, tasks running on the workers may have allocated memory that is not released: global or persistent variables, locked functions, memory leaks or persistent data in MEX files, etc.
After destroying the job or task, you can restart a worker using the RestartWorker property. The memory is then returned to the worker.You can set RestartWorker to true (or logical 1) if you want the job to restart the MATLAB session on any workers before they evaluate their first task for that job.
For example, submitting the following job after your main jobs have finished will force all the workers to restart their MATLAB instances:
function forceRestartAllWorkers(sched)
memFlushJob = createParallelJob(sched, 'RestartWorker', true);
t = createTask(memFlushJob, @() true, 0, {});
submit(memFlushJob);
waitForState(memFlushJob);
destroy(memFlushJob);
end
More information about this can be found at the following URLs:
Best Answer