• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.OutOfMemoryError Exception in thread "main"  RSS feed

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I am trying to run an application based on JavaMail API. But when i run it i get the error:


Even a restart of the PC didn't help. Could you please tell me some ways in getting rid of this? Also some tips on JVM memory saving tips would be helpful! Because i'm not good at resource saving!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide the full stack trace?
Most of the times some infinite loop causes OOME Exception.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no stack trace! The comes in the console part of eclipse and is just two lines which i copied! Nothing else shows up!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well then I would suggest you check your code for infinite recursion
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I checked for infinite loop. I did a debug. I found that the code is exiting somewhere in the middle of its execution. Actually i have a String variable, which grows unusually long as the application goes on! It stores the complete HTML code that is going to be rendered in the mail. Could that be a problem?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing actual code, that could be likely candidate. If possible try to prune the string. Many mail servers have an upper limit on mail/attachment size.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Infinite loops are rarely the cause of OOMEs, unless the loop is allocating objects and adding them to a collection. Most often, it's simply that your program is using too much memory. It's unlikely that it's the HTML, unless you've got multiple megabytes of it. More likely it's something else.

First, it may be that the program simply needs more memory. Add "-Xmx256m" to the vm arguments in the Eclipse run configuration. If it works, then your program just needed more than the default sized heap. If it still doesn't run, then it's probably something that's going out of control. First try reading the code, or better yet, getting someone else to do it, and look for excess memory usage. If that it's enough, then you can use a memory profiler (YourKit, JProbe, etc) to find out where the memory is going.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 256MB memory allocation didn't help! I went through the code. I can post the code here. But the thing is it has 5 classes two of them are big!

Looks like I created a MONSTER!!!

Little explanation that i can provide is that, I am adding string values to variable which stores the whole text of an html page starting from "<html>" to "</html>". But when i debugged the code i see in a loop when the values are getting added to the string, the code suddenly comes back to the main class to finally block and exits and throws the exception. Well seeing from that it looks like the string size is becoming bigger than it can handle!

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you have no logging or anything in the program that can be used to help track down when you run out of memory?!
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i haven't incorporated any logging yet. Thought I would finish the code and do the logging tasks in the end!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!