I am creating a program that will do 67,108,864 calculations using Netbeans. But when I run it, there is an error message: java.lang.OutOfMemoryError: Java heap space.

I have tried several things to overcome this problem:
1. I changed the setting of VM Options of the Project Properties. I even set the VM Options to -Xmx1024m.
2. I changed the setting of VM Options of the Tomcat Server. Here, I also set the VM Options to -Xmx1024m.
3. I disabled the HTTP Monitor.

What I have not tried is changing the content of netbeans.conf file since my computer does not allow me to change it.

So, my questions are:
1. How can I fix this kind of problem in a servlet project?
2. What is the maximum value of Xmx? Is it the capacity of the RAM?
3. How can I change the content of netbeans.conf file?

Environment:
8 GB RAM

  1. How much memory does each calculation need (how many of what kind of objects)?
  2. Do you need to keep all the objects for each calculation?
  3. Is it possible to run a smaller version of the calculation so you can tell whether it is a bug or a genuine problem of scale?
  1. I don't have any idea about this.
  2. I will not keep all the calculation. I will only keep some which match with a condition.
  3. Yes, I have already run the smaller version using smaller data and it worked. So, I absolutely sure that this is a problem of memory.

FYI, in my program I create 3 result sets and two preparedstatements. Can they cause out of memory problem?

It looks like you are creating something as part of each calculation and it's not being garbage collected (because you are keeping a reference to it somewhere). It's hard to say any more without seeing the relevant code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.