Firstly, be sure you are using at least the latest stable NetBeans release with all patches applied.
If yes, you are hitting the issue in JRuby like this one. To workaround it you might increase memory available to the underlaying JRuby process by setting JRUBY_EXTRA_VM_ARGS environment variable before starting NetBeans. E.g. on Linux:
$ export JRUBY_EXTRA_VM_ARGS=-Xmx1024m $ ./bin/netbeans
similarly on Windows.