+ 1

If I instantiate an object inside an array using a for loop, do the objects get destroyed when exiting the for loop?

I was thinking since local variables like int i are destroyed when exiting it might be the same for objects, though I'm not sure and if yes, then how do I keep those objects saved in memory? In my case I'm using 2 loops to iterate through each element (2dimensional array) but I should probably use just foreach, in any case if they get destroyed is there a solution?

12th Feb 2017, 6:46 AM
SIMOMEGA
SIMOMEGA - avatar
1 Odpowiedź
+ 2
If you declare the array within the for loop absolutely yes, but if the array is declared outside the loop and you're just using the loop to instantiate the array then the objects are stored in the array.
12th Feb 2017, 7:16 AM
ChaoticDawg
ChaoticDawg - avatar