Reputation: 489
Assume my code is as follows:
int value=-1;
for(int i=0;i<10;i++)
{
f(value);
}
where f
is a complex function which calls other classes..etc.
I have a performance issue here which makes the IDE (NetBeans) freezes and few minutes later throws a heap size exception. Actually it freezes even for two iterations (i<2)
However, when I sequentially execute
f(value);
I got the answer right away with no exceptions.
How can I overcome such issue? is there any tweak/another way to run f(value)
several times?
Upvotes: 2
Views: 89
Reputation: 353
I think, you need to review your code and related classes of the function f(value);
. As you said, calling it one time is everything correct but for subsequent calls, you are facing heap memory exception. Make the unwanted object eligible for garbage collection, avoid string concatenation, some more tricks to utilize available memory.
Upvotes: 1
Reputation: 1190
It seems that you want to execute the logic of function f
ten times with the same input.
So it will be better to execute it within the function logic rather then calling function f ten times. It will reduce the cost of function call ten times
.
(Not sure whether it will serve your purpose. Just try it.)
Upvotes: 1