No out of memory error but matlab crash

조회 수: 35(최근 30일)
Matt 2023년 3월 16일
편집: Matt 2023년 3월 16일
I use matlab 2022a on ubuntu 20.04.
These two codes crash matlab without generating an error message :
while 1
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 ?
Thank you
  댓글 수: 4
Matt 2023년 3월 16일
No, I tend to believe that when something goes wrong on matlab it's because I misunderstood something rather then I hit a bug. And so far this assumption has proven valid !
I do get the warning you indicated, just for a larger array size because of the amount of ram of my pc. But if I try to ask for more memory then the pc has in severals or 2 attemps (so the first and second example of my last post) matlab crash.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2023년 3월 16일
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
Steven Lord
Steven Lord 2023년 3월 16일
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.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Jan 2023년 3월 16일
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
Jan 2023년 3월 16일
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!

Translated by