In my code creating an object is extremely expensive and the memory required is quite large. I need to create it about a 100 times for testing my product. If I write it as so
for(int i =0; i < length; i++){
Object ob = new Object();
//do something with ob
Object2 ob2 = new Object2();
//do more with ob2
}
Will this create a new ob, ob2 every time the for loop is run? I need them to be set to null at the end of the for loop after execution else my test results will come out wrong. According to this it doesn't matter so I'm slightly confused.
I think it should destroy them at the end of the for loop.