No out of memory error but matlab crash
78 views (last 30 days)
I use matlab 2022a on ubuntu 20.04.
These two codes crash matlab without generating an error message :
end % until matlab crash
a = rand(2048,2048,2000); % ok
b=a; % still ok but if b is really allocated memory should not work on my system
b=a+1; % matlab crash
I would be expecting an out of memory error and not a crash. Is there a reason I do not get an error message ?
Steven Lord on 16 Mar 2023
Did MATLAB crash or did the operating system kill it? Check if there's a message in the log file that the Out of Memory (OOM) killer terminated the MATLAB process. If it did then this is not a bug in either MATLAB or the operating system.
More Answers (1)
Jan on 16 Mar 2023
It is expected, that creating a bunch of large arrays (1st example) crash an application. You cannot do much gainst it, because filling the available memory creates a situation, in which noch enough memory is available to display an error message: this would need memory to open a new figure and even updating the text of the command window costs RAM.
In the 2nd example, the duplication of the array is performed inside a+1. Again there is no reliable chance to predict in advance if the memory is exhausted after the allocation of the additional RAM.
I consider the behavior in both cases as a bug - not of Matlab, but of the operating system. There should be a method to tell the OS: "I need at least this amount of memory for an error message. If an operation does not leave this part free, stop it." But neither Linux, nor Windows, nor any other operating system I know is capable to do so. The same problem is unsolved for file systems: If you fill the drive of the OS until the last byte (or kB usually), the system falls into an undefied state and will show random behavior. Even posting a warning can request some bytes of the disk (caching or logging), such that the power to control the system is lost. For stablility the rule of thumb is: leave 5% of the fisk free - very coarse...
Conclusion: When the memory is exhausted, Matlab (and any other application including the OS) drives into an undefined state. This is a bug and there is no known method to catch the problem reliably in general. Therefore the responsibility remains by the programmer: Check the availability of RAM in advance.
Remember, that this problem does not concern Computers only: Even physical systems suffer from such undefined states due to exhausted resources: A fuel tank can become unusable, if you fill it completely without leaving any gas in it: Then trying to extract some fuel can be prevented by the force of the vacuum.