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