• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

java.lang.OutOfMemoryError Exception in thread "main"

 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic