I have met a Out of Memory problem in my application.
In one of my threads execution, there is a sudden java.lang开发者_开发百科.OutofMemoryError
and make that threads die.
I have already select the memory heap size for the application is 20M. I have dumped out the memory usage for the whole application before and after this OOM on this thread occurs, it does not exceed 20M.
I don't know how to tackle this problem.
So what is the possible causes of that java.lang.OutofMemoryError
? and is there any method to tackle if I don't know the exact reason?
This is what i got! Before this memory usage of the application is 8M
after this memory usage of the application is also 8M.
The cause is that you run out of memory. This might however be one of several kinds so the exact message is important.
You can attach to your running program with jvisualvm (in the JDK) and investigate the object tree to see where the memory went. Hopefully you can deduce why it is still used (can be as simple as a static field holding a copy of the structure) and how to get rid of it.
When you found that, then put in try-finally clauses so that the memory is always released even if an OOM is thrown.
Its likely to be because you didn't give your application enough memory.
I have already select the memory heap size for the application is 20M. I have dumped out the memory usage for the whole application before and after this OOM on this thread occurs, it does not exceed 20M.
The heap size will never be more than the maximum. This is what having a maximum means. ;)
精彩评论