No out of memory error but matlab crash
조회 수: 35(최근 30일)
표시 이전 댓글
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 ?
댓글 수: 4
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.
댓글 수: 2
I couldn't find an Ubuntu-specific page talking about the OOM killer, and the one I posted is a bit old, so I'm not surprised the information is in a different log file than the one named on that page.
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.
댓글 수: 2
Chrome and Firefox control the memory actively, so they are a cery good example. In opposite to a programming language, the browsers can control, how much memory is requested to accomplish a job.
You could write your own memory controller and encapsulate all rand(), zeros(), ones(), ... functions. The wrapper must ask feature memstats if there is a matching free block of memory. But this costs runtime and you cannot go deep enough to catch a+1. Such a wrapper would be equivalent to a measurement of the filled-in fuel to avoid exhausting the resources.
Overflow is a serious problem in all fields of science and numerical maths. It is hard to catch unexpected exceptions.
Find more on Startup and Shutdown 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!