Create error "Failed to reserve space for object heap"

Is there a utility (for Windows) that uses memory so I can create the JVM "could not reserve enough space for the object heap"?

I want to use this memory in a process outside the JVM.

+2


a source to share


5 answers


Just use the -Xms flag

java -Xms3g org.foo.Main

      



The above will try to create an initial 3GB heap size, just adjust it to be larger than your system's total memory (physical and virtual)

+7


a source


I think you can try with this:

String s = "b";
for (int i = 0; i < 1000 000; i++) {
  s+="b";
}

      



Since a newline will be assigned every time the s + = "b" line starts, it must end from the java heap.

-1


a source


List<Object> leak = new ArrayList<Object>();
while(true) {
    leak.add(new Object());
}

      

-1


a source


You can use an arbitrary amount of memory by running several scripts that look like this:

public static void main(String[] args)
{
    List<String> l = new ArrayList<String>();
    for (long i = 0 ; i < 100000000l ; i++)
    {
        l.add(new String("AAAAAAA"));
    }
}

      

With a large enough heap space (e.g. -Xmx1024M). The problem is that any modern OS will try to use virtual memory in order for the application to still function, which will cause your hard drive to start thrashing rather than going out of memory for the JVM. You may need to set the OS shared swap space to something that is really related to this scenario.

-1


a source


Here is a tiny program for you that will consume the number of bytes given on the command line:

#include <stdlib.h>
int main(int argc, char *argv[]) {
  int bytes = atoi(argv[1]);
  char *buf = malloc(bytes);
  while (1) {
    int i;
    for (i = 0; i < bytes; i++) buf[i] += 1;
  }
}

      

-1


a source







All Articles