I have an update Method, that updates the level in the game every ms. Inside this method, i have several for loops that look like this:
for (int i = 0: i < 10; ++i){ }
When i say:
int i = 0
Does that create a lot of garbage? And would there be an alternative?
Thank you
Answer
When you write int i = 0
it creates no garbage.
The variable i
has type int
which is a primitive type, not an object (or reference) type. The state of i
is held entirely within the stack frame of the enclosing method; i.e. not on the heap.
Does that create a lot of garbage?
No.
And would there be an alternative?
No alternative is necessary …