You can set it in NetBeans in the project properties -> Run -> VM options
- Right click on your project “Properties“
- Select “Run” category.
- Enter your arguments(-Xmx512m) in the “VM Options” text box.
Example: Putting -Xmx512m in the “VM Options” text box gives 512Mb maximum heap size to your Java program.