Was java heap memory limited in MATLAB 2025b?
Show older comments
Has anyone else noticed that the java heap memory has been severely limited in MATLAB 2025b? In 2024b it was ~32000MB, now it is ~8000MB. Why the change? This is detrimental for my code and not worth working around. Hopefully this changes back or this is the last straw and I may finally move to Python...
9 Comments
Walter Roberson
on 30 Sep 2025
On my system (MacOS Intel) the breakpoint is R2023b which had a Java Heap preference (under General) that supported ~32000MB, but R2024a instead has a "Java Runtime Environment" preference that is limited to 8192.
Nick
on 30 Sep 2025
John D'Errico
on 1 Oct 2025
Edited: John D'Errico
on 1 Oct 2025
On my Mac OS M4 series, it also shows a limit at 8192, with for me, a default at 1728. So I looked up the JVM ergonomics rules for the heap size.
Default heap sizing on bare-metal systems (pre-Java 10)
- Initial heap size (-Xms): Defaults to 1/64 of the physical memory, with a reasonable minimum of at least 8 MB.
- Maximum heap size (-Xmx): Defaults to 1/4 of the physical memory. For example, on a 4 GB machine, the maximum heap would be 1 GB.
In my case, with 48 GB of physical RAM, 1/4 of that would be 12 GB, but they may also have some other rules that reduced it to 8GB max.
So, when you saw 32000MB as a max, was that on a different machine with more RAM?
Walter Roberson
on 1 Oct 2025
R2023b, MacOS Intel 15.6.1

R2025b, MacOS Intel 15.6.1

Exact same machine, just different versions of MATLAB.
Benjamin Kraus
on 2 Oct 2025
What are you doing in MATLAB that requires such a large Java heap size?
It is worth noting that in MATLAB R2025a, neither the MATLAB Desktop, MATLAB Editor, nor MATLAB Graphics use Java anymore, so the Java heap size is no longer relevant for the performance in those areas. In the past, a frequent reason to increase Java heap size was if you were rendering large amounts of data in a figure, but that no longer uses Java. Java has been removed as a dependency for most of MATLAB, so unless you are explicitly calling into Java from MATLAB, the heap size should be much less relevant than it used to be.
Nick
on 2 Oct 2025
@Benjamin Kraus ", so unless you are explicitly calling into Java from MATLAB, the heap size should be much less relevant than it used to be."
There is no indication at <Java with MATLAB> that calling Java from MATLAB is deprecated by Mathworks and so there is no justification for limiting the user from setting the Java heap as desired/needed to support their use.
MATLAB is a general programming language/development environment; it isn't Mathworks' position to try to control a user's use as they see fit for their needs/purposes. The seemingly increasing penchant for the "big brother" approach is totally missing the point of having the tool; it's up to the user to decide what best suits their situation rather than Mathworks.
I'm sure the thought internally is trying to improve base MATLAB performance by keeping as much memory as possible for MATLAB itself and to make simpler ease of use, and that's an honorable objective, but when it comes at the expense of limiting the ability of advanced users to stretch capabilities, then it goes too far.
If the user makes poor choices, it's on them, not Mathworks (albeit another probable reason for deciding to limit is probably to try to reduce support requests for out of memory errors, granted).
$0.02, im(nsh)o, ymmv, etc., etc., etc., ...
Benjamin Kraus
on 2 Oct 2025
@dpb: Calling into Java from MATLAB is definitely not deprecated. It is still fully support and I am not aware of any plans to change that. That wasn't what I was trying to suggest by my question. I don't know the rational behind changing the upper limit for Java heap size (that is not my team at MathWorks), but it sounds like @Nick is already talking to the right people to answer that question, so I'll let them provide the answer to @Nick.
dpb
on 2 Oct 2025
@Benjamin Kraus - I grok, I just wanted to express my very strong opinion that introducing barriers to the user in how they choose to use MATLAB is misguided direction on Mathworks' part. The external languages interface link was only to emphasize that it doesn't make a lot of sense to continue to support Java and then purposefully try to hamstring it unless there were any such intentions. I did go look at the current documentation just to confirm for myself that no such implications had been introduced.
Hopefully we'll get a report back on the reasoning behind introducing the limitation when @Nick gets an official response.
Accepted Answer
More Answers (2)
Benjamin Kraus
on 2 Oct 2025
Edited: Benjamin Kraus
on 2 Oct 2025
@Nick: Now that you've got an answer from technical support that it was a bug, let's talk potential solutions/workarounds.
Have you tried using a java.opts file to change the maximum memory allocated to the Java heap?
I just did a quick experiment, and from what I can tell it seems to have worked.
I created a new java.opts file in my MATLAB startup directory (following these instructions: "Specifying Java Startup Options", but ignoring the part that says "To adjust the Java heap size on desktop versions of MATLAB, use Java Heap Memory Settings.").
Contents of java.opts:
-Xmx32689m
I then ran this command in MATLAB:
java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments
It showed two copies of "-Xmx", the one from MATLAB's preferences, and the one from java.opts. But the one from java.opts was second, and seems to take precidence over the earlier setting.
I then used the jstat command to verify that the new settings took effect, and they seem to have worked.
Kristoffer
on 8 Jan 2026
0 votes
I wonder if what is displayed in Settings->General->Java Runtime Environment isn't just simply wrong, i.e. this is the bug? Because I can edit the value of the maximum Java heap memory as before in the file matlab.prf (located in the matlab settings folder), and when I restart matlab and run the command
java.lang.Runtime.getRuntime.maxMemory/1e9
it seems to corrently display the new maximum Java heap memory that I entered in the matlab.prf file (in GB). Even though the value in the settings is not updated.
Categories
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!