This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

java.lang.outofmemory Error

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Folks,
I am getting following error almost every week..
java.lang.OutOfMemoryError

I've written folowing program . Is this going to reduce the problem a bit...
_________________________________________________
public class Freemem
{
public static void main (String [] args) throws Exception
{
System.out.println("Total Memory in JVM = " +
s_runtime.totalMemory()+
" Free memmory = " +
s_runtime.freeMemory ());

long upper_limit =
Long.MAX_VALUE;
System.out.println("Maximum value= " + upper_limit);


}

private static final Runtime s_runtime = Runtime.getRuntime ();
} // End of class
_________________________________________________
What criteria I should use in my program which will give me ample of time to resatrt Apache/Tomcat or is there way I can free up memmory automatically.

thanks
SA
 
author and iconoclast
Posts: 24203
44
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
freeMemory() tells you the amount of free memory. It does NOT "free up" memory, or accomplish anything else.
If you're getting OutOfMemoryErrors after running for a while, then you've probably got a "memory leak" in your program. In Java, having a memory leak means your program is keeping references to objects that are no longer being used, so they can't be garbage collected; eventually they fill up all of memory and you get OutOfMemoryErrors.
There are profiling tools that can help you find the leak, but often you can find it by inspection. Have you, for instance, got a Collection as a member variable which, over time, gets more and more data in it?
 
shivani anand
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying Ernest,
I was wondering can I write a program which can tell me object name or program which is causing this error?
Thanks
SA
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
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
As I said, there are tools that do memory profiling that should be able to help you track down the leak: OptimizeIt (now owned by Borland) and JProbe are two well-known ones. There are others, I'm sure. There was a free "HAT" (Heap Analysis Tool) that might also be a help; not sure where to find that these days.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic