1

As the title suggests I'm getting this error inside a thread.

The offending LOCs looks like this:

for (int i = 0; i < objectListSize; i++) {
   logger.INFO("Loop repeat: "+i+" ...", true);
   final Double discreteScore = sp.getDouble(superPeerSocket);
   final int expectedObjectIDs = sp.getInteger(superPeerSocket);
   final String discreteObjects[] = new String[expectedObjectIDs];
   for ( int j = 0; j < expectedObjectIDs; j++)
      discreteObjects[j] = sp.getString(superPeerSocket);
   htPlus.attachInitialDiscreteList2L1(discreteScore, discreteObjects); 
}

The final String discreteObjects[] declaration is where I get the error. I am running this code inside a thread. I have two threads currently active when I get this. I also tried using the MAT tool from eclipse. here is a link with some chart files inside: PLC chart files (dropbox URL)
If anyone has any idea for this problem I would be grateful. P.S.: I am thinking to remove the loop although it just fails in the first loop pass.
(I get this in the output when the program fails)

Expected data size: 10
Repeat: 0 ...
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid3793.hprof ...
Heap dump file created [1404020 bytes in 0.015 secs]
Exception in thread "1" java.lang.OutOfMemoryError: Java heap space
    at planetlab.app.factory.Worker$15.run(Worker.java:796)
    at java.lang.Thread.run(Thread.java:662)

Something irrelevant:
What's with the code not properly formatted/intended error when making posts in stack overflow? It took me 15 minutes to figure out what to do :@ :S :@

8
  • 4
    You should log the value of expectedObjectIDs before creating the array... Commented Aug 28, 2011 at 16:14
  • What value of -Xmx are you using? The heap space usage looks tiny. Re: code formatting, stackoverflow.com/editing-help Commented Aug 28, 2011 at 16:15
  • 2
    And what is the value of expectedObjectIDs? Commented Aug 28, 2011 at 16:16
  • @Jon Skeet: How stupid of me! Don't know how I never thought to log the value! Thnx! :) (at) Matt Ball: Yes, I've seen that but still it's not clear how you should do it ( I believe it would be more concise to say: Highlight code then press Ctrl+K - or maybe I'm weird :) :P :) Commented Aug 28, 2011 at 16:20
  • For history: The value was 1077084160 :P Commented Aug 28, 2011 at 16:21

1 Answer 1

6

Every Java program runs in a sandbox. While your OS might have 10 GB of RAM available to it your app might only have 128 MB.

You need to make sure you app has enough ram allocated to the JVM by using the -Xms -Xmx arguments. -Xms indicates the minimum and -Xmx the maximum

It's been suggested in the comments that your expectedObjectIDs seem kinda high. I would certainly check that out. However, you can use the following code to get an idea as you to memory usage and available memory. Using that info you can adjust your -Xms -Xmx accordingly.

Good luck!

Runtime runtime = Runtime.getRuntime();  

long maxMemory = runtime.maxMemory();  
long allocatedMemory = runtime.totalMemory();  
long freeMemory = runtime.freeMemory();  

System.out.println("free memory: " + freeMemory / 1024);  
System.out.println("allocated memory: " + allocatedMemory / 1024);  
System.out.println("max memory: " + maxMemory /1024);  
System.out.println("total free memory: " +   
   (freeMemory + (maxMemory - allocatedMemory)) / 1024);   
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.