It is still, after more than 25 years, not possilble to stop a running Matlab process and/or clear memory without aborting Matlab externally in many kinds of circumstances. Sorry if I sound frustrated and I genuinely don't mean to be impolite as I'm a dedicated Matlab user, but, well, I think it's pretty reasonable to be frustrated with this behavior at this point. I think that frustration is a reasonable response and a genuine expression of the user reality that I describe below. I express frustration, a frustration which I believe is shared by many users, with the sincere hope that this will get the Mathworks' attention, and that the Mathworks will take it seriously and take on a significant challenge to overcome it. Matlab is a great product, and I believe that that this would really make it much better and in alignment with modern expectations for a development environment.
Please Matlab, solve this problem. Make this a priority. I think it's very clear, and has been very clear to many users for a very, very long time (see below), that this is just not an acceptable way for Matlab to function.
Here is an example of the kind of pretty clearly unacceptable workflows that it leads to (and that I am dealing with curently, and have dealt with many times over decades).
THE MATLAB DEATH LOOP
Load a large dataset into memory, eg a very large table (eg a gigabyte).
Run some code that uses the table.
Need to make a simple change, eg change a line of code.
Attempt to re-run the code. This leads to a complete and indefinite freeze of the Matlab process.
There is no way to stop the running code or clear memory, including ctrl-c, ctrl-break, hitting stop on the editor window, etc. Not even clear.
Only viable option: externally terminate the Matlab process, eg using Activity Monitor on Mac, Task Manager on Windows or a terminal kill command. The same basic issue exists on most or all platforms as far as I'm aware. Sometimes, lose any unsaved changes to code, variables, data, settings, etc.
Start over, re-initialize everything in Matlab that was set up, do whatever processing is required to get to the point of the change (which is sometimes very time-consuming) and do it all again. Then change another line of code, and then do it again. Very, very slow and painful development workflow / way to make progress.
Matlab has many circumstances, especially involving large memory objects, where it gets stuck in some kind of memory management process indefinitely (many minutes). I have also experienced this in other circumstances that don't involve large variables but involve other processes that seem to be able to get Matlab stuck.
Commands like clear to try to start over can just lead Matlab to get stuck in some kind of memory management process indefinitely (again, many minutes). Simlarly for displaying large objects in the object/variable viewer.
There is no way to embed a 'drawnow', a hack that sometimes solves this problem for certain kinds of loops, because commands like clear, load, etc. cannot have a drawnow inserted into them.
There are ways to try to work around this issue, eg avoiding large datasets. That said, I really believe that the issue impacts many users, is really just not an acceptable way for a modern development environment to function, and that it needs to be solved directly in some way. I also believe that a solution would be possible.
I appreciate that there are issues with OS implementations, eg memory management, that make this a challenge. That said, I'm quite sure that there is a better option that the brilliant minds at the Mathworks can come up with than the MATLAB DEATH LOOP. This has been a problem with Matlab for multiple decades at this point.
For me, as a long-term and dedicated Matlab user, it's been by far the biggest problem with Matlab. There is certainly no other IDE/development environment that I work in where I have to do this.
This has been a widely-known problem that impacts many users. Here's an example of a post that has had 1088 views in the last month, and that was from more than a decade ago:
Please consider making this a priority and coming up with a solution to it.