调用 MATLAB JA Builder 编译组件时出现内存不足错误
我在使用 Java 调用 MATLAB JA Builder 编译代码时遇到了一个奇怪的问题。详细信息如下:
- 代码对大型 .mat 文件执行
load()
- 如果在 MATLAB 中打开 mat 文件(通过导入 .mat),则一切正常,并占用约 900MB 的空间内存
- 如果从Java应用程序调用代码(它只是导入由JA Builder构建的函数),我会从MATLAB脚本中耗尽内存
- 我尝试将Xmx设置得非常高,但这似乎根本没有做任何事情
- 更奇怪的是如果 java 程序通过 Eclipse 调试器运行,它最多可以使用 900MB 的 RAM 并且
load()
函数成功
有谁知道会发生什么?
我附上了堆栈跟踪的一部分:
??? Error using ==> load Out of memory. Type HELP MEMORY for your options. ... Matlab M-code Stack Trace ... file C:\Users\HiME\AppData\Local\MathWorks\mcr_cache_v78\fileProcesso_39586D5669D9A968B2CD5231A43620E4\fileProcesso\getHeaders.m,name getHeaders,line at 8. com.mathworks.toolbox.javabuilder.MWException: Error using ==> load Out of memory. Type HELP MEMORY for your options.Error in =>getHeaders.m at 8
I'm having a strange problem with calling a MATLAB JA Builder compiled code in Java. Details are as follows:
- The code does a
load()
on a large .mat file - If the mat file was opened in MATLAB (by importing the .mat), everything works fine and takes up ~900MB of memory
- If the code is called from an Java app (which simply imports the function built by JA Builder), I get out of memory from the MATLAB script
- I have tried setting Xmx really high, but that doesn't seem to do anything at all
- What is weirder, is that if the java program is run through the Eclipse debugger, it can use up to 900MB of ram and the
load()
function succeeds
Does anyone know what could be happening?
I have attached a part of the stack trace:
??? Error using ==> load Out of memory. Type HELP MEMORY for your options. ... Matlab M-code Stack Trace ... file C:\Users\HiME\AppData\Local\MathWorks\mcr_cache_v78\fileProcesso_39586D5669D9A968B2CD5231A43620E4\fileProcesso\getHeaders.m,name getHeaders,line at 8. com.mathworks.toolbox.javabuilder.MWException: Error using ==> load Out of memory. Type HELP MEMORY for your options.Error in =>getHeaders.m at 8
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试设置 -Xmx lower。
在常规 Matlab 进程中,内存分为用于 Java 对象的 Java 堆和可用于 Matlab M 数据结构(如加载结果)的其他内存。增大 Java 堆会调整该分界线,将内存从本机代码和 Matlab 的 GC 中夺走,并将其交给 Java。基本上,Java 堆和 Matlab 堆是在内存竞争。在 JA Builder 库中运行的 JVM 可能以相同的方式工作。
检查您在 Eclipse 下运行的堆大小,并将其与 Java 应用程序正常运行的情况进行比较,并尝试减小 Java 堆大小,以为 Matlab 堆保留更多内存。
Try setting -Xmx lower instead.
In a regular Matlab process, the memory is split between the Java heap used for Java objects, and the other memory available to Matlab M data structures like the result of that load. Making the Java heap bigger adjusts that dividing line, taking memory away from native code and Matlab's GC, and giving it to Java. Basically, the Java heap and Matlab heap are in competition for memory. The JVM running inside a JA Builder library probably works the same way.
Check the heap size you're running with under Eclipse and compare it to how your Java app is normally running, and try reducing the Java heap size to reserve more memory for the Matlab heap.