Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

How to trace an OutOfMemoryError?

Thread view: 
Princess Morgiah - 04 Apr 2004 12:09 GMT
Hi everyone,

I'm stuck with a little application I wrote some time ago. After using it
for a while, the application hangs and an OutOfMemoryError is written to the
console (java.lang.OutOfMemoryError is all that is written).

Since there is no stacktrace, no extra information and thus no way of
knowing where the error comes from, how do I trace this back to it's origin?

I have tried to increase the memory available to the JVM, setting it to a
minimum of 256M and a maximum of 512M, but to no avail. And even if it did
work, this would not be needed - the application itself should be very happy
with a maximum of 1M!

There are some parts of the application that could be at fault - database
stuff, creating a lot of objects, etc... I've had a look at them but all
seems to be in order.

Any ideas?

Princess Morgiah
Ryan Stewart - 04 Apr 2004 13:57 GMT
> Hi everyone,
>
[quoted text clipped - 17 lines]
>
> Princess Morgiah

First, look for infinite loops. Then use a logger to track where you are in
the execution.
Princess Morgiah - 04 Apr 2004 20:39 GMT
<snipped problem of OutOfMemoryError>
> First, look for infinite loops. Then use a logger to track where you are in
> the execution.

Thanks, yours turns out to be very sound advice - I already had a logger in
place but removed some log calls inside pieces of 'trusted code'.

As it turns out, one of those loops kept reading from an invalid stream,
ignoring invalid input without providing a way out, hence the accepting
buffer grew and grew with the expected result.

Thanks again Ryan!

Princess Morgiah
Knute Johnson - 04 Apr 2004 19:29 GMT
> Hi everyone,
>
[quoted text clipped - 17 lines]
>
> Princess Morgiah

Wrap all of the code in:

try {
} catch (Exception e) {
    e.printStackTrace();
}

Signature

Knute Johnson
email s/nospam/knute/
Molon labe...

Inertia_sublimation - 04 Apr 2004 20:37 GMT
> > Hi everyone,
> >
[quoted text clipped - 24 lines]
>      e.printStackTrace();
> }

Isnt java.lang.OutOfMemoryError an Error, and not an Exception?
If so, I think that catch statement should be instead:

catch(Throwable e)

or catch(Error e) if the OP wants to catch only that error.
Princess Morgiah - 04 Apr 2004 20:46 GMT
<snipped problem>
> Wrap all of the code in:
>
> try {
> } catch (Exception e) {
>      e.printStackTrace();
> }

Thanks for the suggestion, I tried it before but it turns out that I was
tracing the wrong part of the code.

A small correction is in place here, however:
--- incorrect ---
public class Oome
{
   public Oome()
   {
       try
       {
           StringBuffer b = new StringBuffer();
           while (true)
           {
               b.append("x");
           }
       }
       catch (Exception e)

           System.out.println("D'oh!");
       }
   }

   public static void main(String [] args)
   {
       new Oome();
   }
}
---

This will never show the famous Simpson quote, yet:
--- correct ---
catch (OutOfMemoryError oome)
{
   System.out.println("D'oh!");
}
---

will give Homer a chance to speak.

Regards,

Princess Morgiah


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.