即使有足够的RAM可用,java.lang.OutOfMemoryError也是如此 [英] java.lang.OutOfMemoryError even if there is enough RAM available

查看:535
本文介绍了即使有足够的RAM可用,java.lang.OutOfMemoryError也是如此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Eclipse编程方式打开一个文件。该文件的关联编辑器在外部插件中定义,我不能控制源代码。



我使用下面的代码片段打开文件。但是我总是得到



异常:从线程AWT-Windows中的UncaughtExceptionHandler抛出的java.lang.OutOfMemoryError

我试图增加eclipse运行配置的可用内存,但这没有帮助。任何想法可能导致什么?

  private void openFiles(final ipath filePath){
PlatformUI.getWorkbench()。 getDisplay()。asyncExec(new Runnable(){

@Override
public void run(){

IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFile iFileInput = workspace.getRoot()。getFileForLocation(filePath);

IEditorInput editorInput = new FileEditorInput(iFileInput);

IWorkbenchWindow window = PlatformUI.getWorkbench()。 getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
try {
iFileInput.refreshLocal(IResource.DEPTH_INFINITE,null);
} catch(CoreException e1){
e1.printStackTrace();
}
try {
String editorID =xxxxx;
IDE.openEditor(page,editorInput, editorID);
} catch(PartInitException e){
e.printStackTrace();
}

}
});
}


解决方案

尝试增加堆内存大小:



如果您正在开始使用命令行

  java -Xms< ;初始堆大小> -Xmx<最大堆大小> 

您还可以通过eclipse来做,只需在eclipse.ini中添加以下行或通过eclipse gui配置:

  -Xms1024m 
-Xmx1024m
-XX:MaxPermSize = 256M


I am trying to open a file in eclipse programmatically. the associated editor for the file is defined in an external plugin which I don't have control over the source code.

I use the code snippet shown below to open the file. However I always got

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "AWT-Windows"

I tried to increase the memory available for eclipse run configuration, but that didn't help. Any ideas what can cause this?

    private void openFiles(final IPath filePath ) {
    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {

            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IFile iFileInput = workspace.getRoot().getFileForLocation(filePath);

            IEditorInput editorInput = new FileEditorInput(iFileInput);

            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            IWorkbenchPage page = window.getActivePage();
            try {
                iFileInput.refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException e1) {
                e1.printStackTrace();
            }
            try {
                   String editorID = "xxxxx";
                   IDE.openEditor(page, editorInput, editorID);
            } catch (PartInitException e) {
                e.printStackTrace();
            }

        }
    });
}

解决方案

Try to increase heap memory size:

If you are starting using command line

java -Xms<initial heap size> -Xmx<maximum heap size>

You can do it also through eclipse, just add the following lines in eclipse.ini or through eclipse gui configuration:

-Xms1024m   
-Xmx1024m   
-XX:MaxPermSize=256M    

这篇关于即使有足够的RAM可用,java.lang.OutOfMemoryError也是如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆