Eclipse and Java heap space (plus .dll)!!!

本文探讨了如何解决Java程序中出现的“OutOfMemoryError”问题,并提供了多种配置JVM堆内存的方法,包括通过修改eclipse.ini文件、命令行参数以及在Eclipse IDE中为特定程序设置VM参数。

I got this problem "java.lang.OutOfMemoryError: Java heap space" a lot and search a lot these days, just because there are recursive calls in my program. Many people have suggested the options:

 

1, change file "eclipse.ini" for the values of this part "-Xms40m-Xmx256m";

 

2, command line input: "eclipse -vmargs-Xms256m-Xmx50g".

 

(See how much memory I specified? 50g!)

 

I once thought they worked, especially the second one. I just realized that the second one did not, because eclipse never complains, even if I set 50g for the heap size (while my slow machine only has poor 2g memory). I remember that some lab machines do say that it cannot create JVM because the heap size I specified is too big when I use command line setting. Maybe that is the version problem. The eclipse in my machine is 3.2 while the  lab one is latest (), which you do can set the size in command line.

 

I switch to the setting in the Run configuration window of the program I want to run (The second text field special for "VM arguments "). It worked, and complained when I set even over 1208m, considering my physical memory is just 2g. It seems really to be the place to specify the heap size of JVM for the program that you are running, instead of every program in eclipse. And I think it is better to specify it here instead of setting the whole eclipse or the "default" JVM for your whole system.

 

=====================================

 

I got another problem for a ".dll" used in eclipse. Mostly when writing Java program, I just import the ".jar" package. But there is an old program that uses a ".dll" and when I imported the whole program as a projuect, there are some reference error. I did not know where to specify the position of this ".dll" file until I googled.

 

In the "Java Build Path"--"Libraries", click the ".jar" file you added before. There is a Native library location . That is the place to enter the location of the ".dll" file, with such a prompty "Enter the location of a folder containning the native libraries used by 'xxx.jar':"!!

<think> 由于用户的问题涉及到Fortran运行时错误,显示ntdll.dll!RtlReportCriticalFailure,这是一个Windows系统级别的错误。通常,这类错误与内存访问违规、堆损坏或系统DLL问题有关。结合用户提供的引用(虽然引用内容是关于浏览器mshtml模块的汇编代码,与当前问题无关)可以忽略该引用,专注于解决Fortran运行时错误。 解决思路: 1. 检查代码:确保Fortran程序没有内存泄漏、数组越界、未初始化变量等常见错误。 2. 更新编译器和运行时:使用最新版本的Fortran编译器,并确保运行时库正确安装。 3. 检查系统更新:确保Windows系统已更新到最新版本。 4. 调试工具:使用调试器(如Visual Studio)捕获崩溃点,分析调用栈。 5. 依赖项检查:确保程序依赖的所有DLL文件都存在且版本匹配。 具体步骤: 步骤1:检查Fortran代码 - 使用编译器提供的调试选项(如gfortran的`-g`,Intel Fortran的`/check:all`或`/debug`)重新编译程序,运行以捕获错误位置。 - 重点检查动态数组、指针、子程序参数传递等容易出错的地方。 步骤2:更新编译器和运行时库 - 如果使用的是Intel Fortran,请安装最新版本的Intel® oneAPI工具包。 - 如果使用的是gfortran,请更新到最新版本(如通过MinGW-w64或MSYS2安装)。 - 确保程序运行时,对应的Fortran运行时库(如libifcoremd.dll, libgfortran-*.dll)在系统路径中或与可执行文件在同一目录。 步骤3:安装Windows更新 - 打开Windows设置,检查更新,安装所有可用的更新。 步骤4:使用调试器 - 使用Visual Studio(安装C++和Fortran调试工具)打开项目或可执行文件。 - 在调试模式下运行,当崩溃发生时,查看调用栈,定位到出错的源代码行。 - 注意:如果错误发生在ntdll.dll中,这通常是系统底层捕获的异常,需要回溯到应用程序的调用栈。 步骤5:检查DLL依赖 - 使用Dependency Walker(http://www.dependencywalker.com/)或Visual Studio的dumpbin工具检查程序的依赖项。 - 确保所有依赖的DLL都存在,并且没有版本冲突。 其他可能的原因和解决方案: - 堆损坏:可能是由于程序中多次释放同一内存或越界写入导致。使用编译器的堆检查选项(如Intel Fortran的`/check:stack`)或工具DrMemory、Valgrind(Linux下,Windows可用DrMemory)进行检查。 - 多线程问题:如果程序使用多线程,确保线程安全,特别是共享变量的访问。 - 第三方库:如果使用了第三方库,确保这些库与当前编译器和系统兼容。 示例:使用gfortran编译时开启调试选项 ```bash gfortran -g -fcheck=all -o myprogram myprogram.f90 ``` 如果以上步骤无法解决,可以尝试在Fortran社区(如Intel Fortran论坛、Stack Overflow)提问,提供详细的错误信息、操作系统和编译器版本以及最小复现代码。 相关问题: 1. 如何调试Fortran程序的内存错误? 2. 如何更新Fortran编译器? 3. Visual Studio如何调试Fortran程序? 4. 如何检查Windows程序依赖的DLL? 5. Fortran程序常见的运行时错误有哪些? </think> ### Fortran运行时显示`ntdll.dll!RtlReportCriticalFailure`的解决方案 这个错误通常是内存访问冲突、堆损坏或系统资源问题导致的,以下是系统性的解决步骤: #### 1. **检查内存访问问题**(最常见原因) - **数组越界检测**:使用编译器调试选项重新编译 ```bash ifort /check:all /traceback your_program.f90 ! Intel Fortran gfortran -fcheck=all -g your_program.f90 ! GNU Fortran ``` - **指针安全**:检查未初始化指针、悬空指针或非法指针运算 - **检查子程序参数传递**:确保数组维度匹配,尤其是隐式接口过程 #### 2. **更新运行环境** - **编译器更新**: - Intel® oneAPI:升级至最新版([下载页面](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html)) - gfortran:通过MinGW-w64更新([MSYS2仓库](https://www.msys2.org/)) - **安装Microsoft运行时库**: - 下载最新[Visual C++ Redistributable](https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0) - 修复现有安装:命令行执行`sfc /scannow` #### 3. **堆损坏排查** - **启用调试堆**(Windows): ```bash set _NO_DEBUG_HEAP=1 # 关闭调试堆 set DEBUG_HEAP=1 # 开启详细堆检查 ``` - **使用内存调试工具**: - [Application Verifier](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/application-verifier)(选中`Heaps`和`Memory`检查项) - [Valgrind](https://valgrind.org/)(需通过WSL运行) #### 4. **第三方库冲突处理** - **依赖库检查**: ```bash depends.exe your_program.exe # 检查DLL依赖关系 ``` - **隔离测试**: - 临时重命名可疑DLL(如`ntdll.dll`除外) - 使用纯净虚拟机环境测试 #### 5. **系统级修复** - **DEP配置**: 1. 系统属性 > 高级 > 性能设置 2. 数据执行保护选项卡 > 添加Fortran程序 - **注册表修复**: ```reg Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management] "FeatureSettingsOverride"=dword:00000003 "FeatureSettingsOverrideMask"=dword:00000003 ``` #### 6. **代码加固措施** ```fortran ! 示例:安全内存分配模板 integer, allocatable :: buffer(:) allocate(buffer(1000), stat=ierr) if (ierr /= 0) then write(*,*) "内存分配失败!" stop end if ! ... 使用buffer后 ... deallocate(buffer, stat=ierr) ! 显式释放 ``` > **关键建议**:在64位系统上编译时始终使用`/integer-size:64`(Intel)或`-fdefault-integer-8`(gfortran)选项,避免32位整数溢出[^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值