OutOfMemoryError
Hi There,
Any one please tell me how do i identify exactly after/during the execution of which particular statement the OutOfMemeoryError occurs.
I know why the OutOfMemoryError occurs, I am just trying to identify the fix for the OutOfMemoryError, so would like to know when does this happen exactly.
Let us take the below code snipet as an example
try{
statmt1;
statmt2
statmt2;
statmt3;
.
.
.Stattmtn
}catch(Throwable t){
if(tinstanceof OutOfMemoryError){
System.out.println("Oops, No more Memory, please terminate me");
}
}
I want to know which statemenet would throw this exception
[1009 byte] By [
toLearna] at [2007-10-2 7:44:57]

Hello,
first, I do not know of a way to identify the statement at which the OOM is generated.
Second, I want to indicate that the exact statement where this occurs (the suspect) often is not the culprit that causes your problem.
If you have one statement that consumes most of your memory and afterwards a simple statement that takes just the little bit that you do not have, then the second statement throws the exception, though you should optimise the first one.
For a superb explanation of OutOfMemory have a look at:
http://www.szegedi.org/articles/memleak.html
Yours,
Stephan
Try using the Runtime Object to calculate the available memory after each statement's execution(maybe along with a sleep). If gc does not run in the mid, you should get a fairly good idea about the exact statement which causes the trouble. You can cross-check the free memory with the total available memory of the jvm.
There are tools to detect this called profilers. JProfile is a popular one. It should be able to tell you not only how much memory a given method is consuming per execution, but also the perecentage of processing time any given method executes.
Candidates to look for memory issues on your own:
> Dynamically sized arrays (the variable might be *huge* that you pass in as the array size)
> Recursion and collections (adding to a collection in a loop that may call itself)
- Saish
Saisha at 2007-7-16 21:30:23 >
