MATLAB Answers

Does Matlab r2017a manage memory differently than r2016b? (out of memory issues)

8 views (last 30 days)
Jim Kukurin
Jim Kukurin on 11 Sep 2017
Commented: moodyds on 2 Oct 2018
I recently inherited a set of Matlab scripts that analyze some fairly large datasets. They were written on a Windows 10, core i5 x64 system with 8GB of RAM using Matlab R2016b, and ran to completion without issue. After setting up a new system (Windows 10, core i7 x64, 16GB RAM), I installed Matlab R2017a and ran into "out of memory" errors running the same set of scripts that worked fine on the older system.
Specifically, both systems cruise along for most of the script with Matlab using ~4GB of memory. At a specific point in the script that requires additional resources, the "old" system (r2016b) manages to allocate an additional ~2GB of memory (thereby using ~6GB out of its total 8GB), while the new r2017a system (with 16GB total, and a full 8GB remaining either free or in standby) throws an "out of memory" error instead. The dataset used is identical in both cases.
The behaviour is the same after Windows has freshly booted, with no other applications running. Importantly, I have now also installed r2016b on the new machine, and the scripts run to completion in r2016b without issue (so it would appear that it is the version of Matlab, not the new hardware or some sort of windows misconfiguration that is causing the problem).
While I am well aware of the benefits of optimizing memory management, particularly with large datasets, that is not the question I need answered at the moment (I will dig into optimization down the road, regardless). The specific issue I would like to resolve is whether Matlab 2017a handles memory allocation differently than 2016b, and/or if there is some configuration option I might be unaware of that could account for this difference? I could stay on r2016b for a while (or install multiple versions), but I'd rather deal with the cause of the problem rather than avoiding it.
Thank you to anyone who might have some ideas on this.

  1 Comment

moodyds
moodyds on 2 Oct 2018
I am experiencing a similar situation. Have a Windows 10 machine with 128GB of memory. When I boot Matlab up, it states that it only sees 24GB of memory available for all arrays event though my system shows more than 70GB of memory available. I have increased the JAVA heap size to its max and removed any limit on array size. I rebooted Matlab as it said to do and I continue to see a limit of 24GB even though more than 70GB available.

Sign in to comment.

Answers (1)

Philip Borghesani
Philip Borghesani on 12 Sep 2017
There were no global changes in how R2017a manages memory. I expect your problem is due to a change in one function. What function throws the error (post full error message and stack) and can you verify the inputs are the same in both versions of MATLAB?
The more information you can supply about your code and error the more likely you are to receive a helpful response here.
There are two settings that control memory limits and use but it does not sound like you are bumping into one of them.
  1. Java heap size
  2. Array size limit

  2 Comments

Jim Kukurin
Jim Kukurin on 20 Sep 2017
Hi Philip,
I'm afraid I can't give you a complete answer right now, as I have simply been using R2016b instead due to some rather inflexible deadlines.
However, what I can tell you is that the error occurred any time I tried to add a colorbar to a figure. I know colorbar usage/syntax changed a bit in R2017a, so while an error was not unexpected there, I was surprised that it was an out of memory error. However, after a quick commenting out of the colorbar calls for every figure, I then received the out of memory message when performing image segmentation using the otsu function.
In both cases, it was the same message (the generic "Out of memory, the most likely cause is infinite recursion" one). Since the two functions were (to my eye) completely unrelated, and Matlab did not appear to actually be requesting more memory than the system had available, I thought it might be a global memory handling issue, and decided it might be more productive to ask here rather than dig too much further into the issue.
If I get a chance to take another look into the issue on 2017a, I'll try to post some more details. In the meantime, I hope this limited information will be useful to you if there are any other reports of memory issues.
Thanks,
Jim.
Philip Borghesani
Philip Borghesani on 8 Nov 2017
That error message is not a generic out of memory error. It is a stack overflow, which is most likely caused by infinite recursion but could also be caused by an out of memory condition preventing the stack from growing. Before running the code issue dbstop if caught error and when the debugger breaks type dbstack and observe.
If there are too many exceptions happening in your code you can try:
dbstop if caught error MATLAB:lang:StackOverflow
It is possible that this error id is not correct for your version of MATLAB to find the correct id issue lasterror from the command line after experiencing the error.

Sign in to comment.

Products