Does MATLAB have an exit event?

Is there any way to know when MATLAB comes out? I would like to do some work, for example, free some resource, print some logs ... I could add some code to some class destructors. But since we cannot determine the order that MATLAB calls destructors, I am not sure which one is the last, so I can free the resource.

Can we register a MATLAB exit event callback if such an event exists ...?

+4
source share
2 answers

There is no exit event that I know about what was selected when exiting a function or MATLAB itself. However, you can do two things to handle the final cleaning:

+8

finish.m.

startup.m, MATLAB ( MATLAB) .

onCleanup. , , . , :

fid = fopen(filename, 'r');
OC = onCleanup(@() any(fopen('all')==fid) && fclose(fid));

% ...file reading and processing here
% ERROR HAPPENS HERE!
% ... more processing here

fclose(fid);

fid - , fclose(fid) . , OC MATLAB .

+6

Source: https://habr.com/ru/post/1662326/


All Articles