Advice on Heisenbug causing crash in code

1 view (last 30 days)
Paul Johnson
Paul Johnson on 8 Sep 2022
Answered: Shivam Lahoti on 20 Oct 2023
Hi
I keep on getting a matlab crash when running a matlab script I have that routes simulink models using JSON data.
It's an odd bug as when i attempt to run the script in debug mode slowly the crash doesn't occur.
This suggests to me there is some form a memory management problem. Does anyone have any advice?
Should I institude delays in my code with a timer? Are there methods that i should be using to control these sorts of errors?
Thanks

Answers (1)

Shivam Lahoti
Shivam Lahoti on 20 Oct 2023
Hi Paul,
From what I can understand, you are getting a MATLAB crash while running a script that routes Simulink models using JSON data. The script runs successfully when run in debug mode.
The crash could be due to multiple reasons and as you pointed out it might be a memory management problem. MATLAB has a tool named MATLAB Profiler, which creates reports of the runtime of MATLAB code, broken down by individual function calls.
The profiler is primarily designed to analyze the runtime behavior of your code, identify performance bottlenecks, and suggest areas for optimization. However, if the crash is related to excessive memory usage or inefficient code that leads to out-of-memory errors, the profiler can help you identify memory-intensive operations or memory leaks that may contribute to the crash.
Have a look at the following documentation to understand how to use the MATLAB profiler.
  • the profiler will display a summary of the runtime behavior and performance metrics.
  • Analyze the profiler results, focusing on areas such as function execution time, memory usage, and function call hierarchy.
  • Look for any performance bottlenecks, memory-intensive operations, or functions that consume excessive memory.
This might not directly tell the cause of the crash but might point to some sections that might be the cause of the crash, later the code could be modified and check for the compatibility report to debug the section.
I hope this helps.
Regards,
Shivam Lahoti.

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!