java.lang.OutOfMemoryError even if there is enough RAM available

孤人 提交于 2019-12-13 18:30:08

问题


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();
            }

        }
    });
}

回答1:


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    



回答2:


You're guessing without data.

Get a profiler like VisualVM and see what's going on with memory.

Java VM uses a generational memory model. You could have plenty of physical RAM and heap space set adequately, but still get an OOM error if perm gen fills up. See if that is happening to you.



来源:https://stackoverflow.com/questions/25348511/java-lang-outofmemoryerror-even-if-there-is-enough-ram-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!