Reputation: 118
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 i.e. 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();
}
Upvotes: 1
Views: 255
Reputation: 118
Thanks for the support guys, actually my problem was resolved after garbage collecting manually by calling System.gc() statement.
Upvotes: 0
Reputation: 66891
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?
Upvotes: 1