I have String[] inputMsg declared outside a loop and inside a loop I have
inputMsg = new String[someSize];
Since the loop can loop lots of times, I find it out that creating new String[someSize] everytime realy wasteful so in the of each iteration of the loop I would like to remove that memory allocation or to delete it’s content so the inputMsg will be null.
How can it be done in Java?
I have String[] inputMsg declared outside a loop and inside a loop I have
Share
Why declare it outside a loop?
The GC will take care of freeing the memory. If the GC turns out to be a bottleneck, and you have the numbers to prove it, then we can talk some more. But, it turns out most GCs are fairly efficient at reclaiming short-lived objects.