简体   繁体   中英

Memory issue in Java

I've a multi-threaded program which deals with lots of String manipulations and after few hrs of executions the memory exceeds and cause the "java.lang.OutOfMemoryError: Java heap space" issue. And I've already utilized my whole memory to the java program ie 16 GB.

For the test I've created following sample program to understand the issue and its doing the same issue, after just re-initializing a string builder few thousand times it consumes more than 5-10MB of memory, can anyone pls help to overcome this issue.

StringBuilder strObj = new StringBuilder();
for(int i=0; i<50000; i++) {
    strObj = null;
    strObj = new StringBuilder();
}

In what sense does it consume 5-10MB of memory? you're allocating that much here. Java is not going to bother reclaiming it until it needs memory. This can't be causing OutOfMemoryError , not this type of code.

So, why not actually show the kind of code that is causing the OOME?

感谢支持人员,实际上我的问题在通过调用System.gc()语句手动进行垃圾收集后得以解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM