Search code examples
memoryvirtualjavac

Javac -Xmx to limit VM usage


Is there any way to limit maximum virtual memory usage of javac?

When running java, I can run it with "-XmxAm" (where A is number of free megabytes) to limit it.

Is there anything for javac like that?


Solution

  • You can give the same runtime options to javac (and most java programs with an own native starter) by using -J options. By convention, all such options are passed directly to the runtime system. So, in your case, you can invoke

    javac -J-Xmx5m -J-Xmx4m  <source>
    

    to run javac with very little memory. Of course, as reseter said, it is of limited use this way, since javac may really need some amount of memory to compile. On really big projects, you may want to increase the memory this way, though.