Click to See Complete Forum and Search --> : Exception


prone
August 9th, 1999, 11:44 AM
I've almost completed a java app but somehow managed to avoid the handling of OutOfMemoryException. can someone suggest a way that i can go about handling this exception now that my app has been written almost complety. it seems that it can be thrown from anywhere in the app so i'm kinda confused as to where or how i should start. thanx a bunch!

- p

varbsjava
August 10th, 1999, 12:06 AM
Hi,
I think u r taking about OutOfMemoryError.
This occurs because your JVM is not able to allocate memory for objects that u have created in your program. When the JVM is started, the size of the heap(memory allocation pool) is 1MB. If all the memory is used then OutOfMemoryError will occur. So in order to prevent this u have to follow any of these things.

1) See to that u won't create unnecessary objects. Also keep an eye on the scope of each and every variable you create. Make your objects equal to null if u won't need them. If yours is a big application, Garbage Collector will be called before your application exits and it will release the objects references which are not needed by the program.
2) Explicity call garbage collector. But u have to careful in this case. U have see whether u have objects to be freed.
3) Use java -Xms2M -Xmx6M className to start your application.
ms - minimum size of heap.
mx - max heap size.

I hope this will help u. Sorry if it won't.

regards,
arun...