1function bytes = lineGetAvailableMemory()
2% LINEGETAVAILABLEMEMORY Portable available-physical-memory probe (bytes).
4% Routes through
the JVM OperatingSystemMXBean that MATLAB ships on every
5% platform, so
the same code path returns a valid figure on Windows, macOS
6% and Linux without parsing /proc. Falls back to a conservative constant
if
7%
the bean or method
is unavailable (e.g. MATLAB started with -nojvm).
9% Mirrors jline.solvers.ctmc.MemoryGuard.getAvailableMemoryBytes (JAR) and
10% line_solver ... memory_guard.get_available_memory_bytes (Python native).
12FALLBACK_BYTES = 1 * 1024^3; % 1 GB
13bytes = FALLBACK_BYTES;
16 osb = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
18 % JDK <= 13: getFreePhysicalMemorySize; JDK >= 14: getFreeMemorySize
20 v = osb.getFreePhysicalMemorySize();
23 v = osb.getFreeMemorySize();
28 if ~isempty(v) && v > 0