I have Simple Forever Loop like this into the System this is MVCE Example of my System.
public static void main(String args[]){
while (true) {
String string = new String("Hello World");
System.out.println("String " + string);
}
}
according to the OOPS there will be new Object that will be created in all the iteration that will take place. and till that memory will not be free then it will run out of heap space error.
then how could i prevent the CPU for that and how could i overcome that problem.
Similarly I have for the literal like this.
public static void main(String args[]){
while (true) {
String string = "Hello World";
System.out.println("String " + string);
}
}
for the second case if there is all time referenced only one literal which is created in string constant pool. then it should not be give out of memory error.
but i am not getting how it prevent the error that coming.
Please i like to have your Suggestion for the same i have read much of the principals of the oops and that is what i have as confusion.