When I profile my apps, I make sure that the code like this one:
private void Update(){
int count = GetEnemyCount();
}
get's converted to this one:
private int count;
private void Update(){
count = GetEnemyCount();
}
to prevent memory allocation and the heap expansion.
But what about the static methods, and allocations inside them?
Let's take this example (and assume I call it in Update()):
public static float GetPercentPositionX(Transform transform)
{
float result;
int screenWidth = GetScreenWidth();
// some operations, result allocation, screenWidth usage
return result;
}
What do I do here? Does it behave like a non-static function and expands the memory?
Shouldn't I declare static variables inside that class, to allocate the heap space at the start, for vars: result & screenWidth, just like I do in classic, non-static ones?
int count = GetEnemyCount()causes heap expansion? \$\endgroup\$