What happens on Ctrl + C?
Show older comments
I have a problem that my code becomes slower with each iteration (I used a profiler, it is none of the usual culprits: unclosed figures or non-preallocated arrays). If I click Ctrl+C and continue where I started, it runs quickly again. Can someone please tell me what exactly happens on Ctrl+C? I tried writing my variables into a file, clearing all and re-starting, but it didn't help. I would like to know which function is called on this command so I can reproduce this behavior.
6 Comments
Stephen23
on 4 Dec 2017
"..clearing..."
You should be writing functions, not scripts.
Tiko
on 4 Dec 2017
As I understand it, a Ctrl-C raises an interrupt flag and makes matlab stop the running code the next time it's able to check for said flag.(this differs for unix and windows) When the interrupt is detected, it stops the execution of your code, unstacks the stack (recording the line of execution it was in each function) and returns to the workspace.
Edit: I can't tell you which function is being called. I don't think this is accessible code.
About your programm I can only guess what's wrong without the actual code. From my experience, if a programm becomes slower and slower with each iteration, the most likely problem is an increasing need for memory or a recursive call that requires more and more memory for the stack.
When you use clear in a function, all you do is clearing the "workspace" of the current function. This is not the same as clearing all memory that is beeing using by your programm. So I think it would be best to have a look at your memory use. Bring up the task manager and observe the memory or better do it programmatically and try to find out if there is a memory leak or not. But again, this is only me guessing. Without the actual code there is not much we can help.
Tiko
on 4 Dec 2017
Philip Borghesani
on 4 Dec 2017
Some additional information would help here: What MATLAB version are you using and are you using any custom MEX files?
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory 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!