Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans OutOfMemoryError: Java heap space, code formatting

Tags:

java

php

netbeans

When I format code in netbeans, I recently started getting an "OutOfMemoryError: Java heap space" error.

I've been using netbeans for well over 2 years and this just started happening on the typical machine I develop on. Currently using version 6.9, on an XP machine, 4Gb memory. I have adjusted -J-Xmx to 1024m and even tried 2048m, and it still get errors.

This is a small php script, less than 100 lines. I have had no problem in the past formatting 10,000+ lines without editing -J-Xmx or anything else. I am not running any code or debugging or unit testing or anything, just the built-in Source -> Format.

I've tried removing code to see if there was a specific section that is causing problems. From what I can gather, if I add a single control structure, no matter what it contains, I get a memory error.

Even:

if($i == 1) {}

causes the memory error. If I check memory usage, Netbeans has no problem using up all of the memory it can. Any help on this would be appreciated.

Here's the stack trace generated when I get the error:

java.lang.OutOfMemoryError: Java heap space
    at org.netbeans.modules.php.editor.indent.FormatVisitor.addFormatToken(FormatVisitor.java:1002)
    at org.netbeans.modules.php.editor.indent.FormatVisitor.visit(FormatVisitor.java:859)
    at org.netbeans.modules.php.editor.parser.astnodes.Program.accept(Program.java:92)
    at org.netbeans.modules.php.editor.indent.TokenFormatter$1.run(TokenFormatter.java:354)
    at org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:314)
    at org.netbeans.modules.php.editor.indent.TokenFormatter.reformat(TokenFormatter.java:344)
    at org.netbeans.modules.php.editor.indent.PHPFormatter.reformat(PHPFormatter.java:129)
    at org.netbeans.modules.csl.core.GsfReformatTask$1.run(GsfReformatTask.java:105)
    at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:154)
    at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:138)
    at org.netbeans.modules.parsing.impl.TaskProcessor$1.call(TaskProcessor.java:200)
    at org.netbeans.modules.parsing.impl.TaskProcessor$1.call(TaskProcessor.java:197)
    at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:160)
    at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:227)
    at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:66)
    at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:197)
    at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:106)
    at org.netbeans.modules.csl.core.GsfReformatTask.reformat(GsfReformatTask.java:95)
    at org.netbeans.modules.editor.indent.TaskHandler$MimeItem.runTask(TaskHandler.java:550)
    at org.netbeans.modules.editor.indent.TaskHandler.runTasks(TaskHandler.java:317)
    at org.netbeans.modules.editor.indent.IndentImpl.reformat(IndentImpl.java:320)
    at org.netbeans.modules.editor.indent.FormatterImpl.reformat(FormatterImpl.java:190)
    at org.netbeans.editor.ActionFactory$FormatAction$1$1.run(ActionFactory.java:1683)
    at org.netbeans.editor.GuardedDocument.runAtomicAsUser(GuardedDocument.java:344)
    at org.netbeans.editor.ActionFactory$FormatAction$1.run(ActionFactory.java:1651)
    at org.netbeans.modules.progress.ui.RunOffEDTImpl$1.run(RunOffEDTImpl.java:160)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1957)

Looks like there are a ton of similar reports to this issue: http://statistics.netbeans.org/analytics/exception.do?id=472651

Installed 7.0b and reinstalled JRE 6... which is now working fine. Using 7 as 6.9 is unusable when using code formatting. Would still like to figure out how to fix this issue though.

like image 485
Jestep Avatar asked Jan 25 '11 23:01

Jestep


People also ask

How do I fix Java Lang OutOfMemoryError Java heap space?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

What causes Java Lang OutOfMemoryError Java heap space?

lang. OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.

What happens when Java runs out of heap space?

OutOfMemoryError is a runtime error in Java which occurs when the Java Virtual Machine (JVM) is unable to allocate an object due to insufficient space in the Java heap. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java. lang.


1 Answers

I found this NetBeans bug which reports a problem which sounds similar to yours. It turned out that the problem was to do with SVN, and was cured by clearing out an SVN cache directory. Read through the bug's "comments" for the details.

like image 71
Stephen C Avatar answered Oct 26 '22 16:10

Stephen C