> "Adam Maass" <adam.nospam.maass@comcast.net> wrote in message
>> > Is it possible to catch java.lang.OutofMemoryException ?
[quoted text clipped - 10 lines]
> only reason to catch it is to die gracefully. However, in a server the #1
> rule is "Don't die", so it's far from a bad idea to try it.
The problem with trying to catch OutOfMemoryError is that it could occur
*anywhere* there's an allocation (ignorning for the time being that the
class also represents certain other hard limits imposed by the OS that have
been exhausted -- threads and graphics handles comes to mind). In
particular, in a multi-threaded application, we don't know that the thread
that gets an OutOfMemoryError will have the knowledge necessary to release
enough references to make things OK.
My first instinct is that I'd rather have a server application die with a
nice stack trace than limp along producing spurious results. I might be
convinced otherwise for certain situations...
-- Adam Maass
iamfractal@hotmail.com - 19 Jan 2006 08:37 GMT
"I'd rather have a server application die with a
nice stack trace than limp along producing spurious results"
Yes, and that's the point: how do you get this nice stack trace?
OutOfMemoryError does not print a nice stack trace by defualt.
If you want it, you're going to have to catch it, and manually dump it
to a file (presuming you don't want to squirt it onto a screen and hope
it's still there next day).
Catching OutOfMemoryError's, as has been said on this thread, is almost
invariably not an attempt to correct anything, just to perform
precisely this kind of post-mortum data.
Even for a GUI. Would you rather you application just die, or print,
"Out of memory," and then die when you click, "OK?" At least with, "Out
of memory," the user knows he should load fewer
files/analysis-branches/whatever.
.ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition.