4

I have not thought so much of this before I started learning c++ and I have not needed to terminate matlab from a program so many times before. The question just occured to me:

Are there any perils in using the functions quit and exit in matlab? I know that these functions should never be used except for emergencies in c++. However, in my little dream world matlabs functions are in most cases stable which speaks towards that matlab do a successful cleaning of resources even in the case where exit or quit is called. As always this kind of documentation is a bit hard to find for matlab. I am also curious if the same principles applies for both windows and linux.

In case no cleaning is done here, are there any way to fix it? Like creating the file finish.m and letting it contain only a clear all call or so?

BR/Patrik

patrik
  • 4,506
  • 6
  • 24
  • 48

1 Answers1

4

Unlike c++, Matlab has its own garbage collector that takes care of all the "cleaning" stuff for you. So, when you exit or quit Matlab resources are cleaned for you (!)
If you are using some custom data types or you have data you want to save prior to exit you'll need to take care of them by yourself. You can define a custom script containing commands to be executed upon terminating Matlab, see finish for more details.

Shai
  • 111,146
  • 38
  • 238
  • 371
  • Is there any difference between clicking GUI close button and executing exit (or quit)?? Is finish.m executed by clicking GUI x button? – Zeta.Investigator Aug 13 '16 at 11:47