This is a question pertinent to languages that have garbage collection: example1:
public int CalculateSomething()
{
//otherstuff
int something = CalculateIt();
return something;
}
vs example2:
public int CalculateSomething()
{
//otherstuff
return CalculateIt();
}
I want to name the variable so I can more easily see it in the debugger mode, but a colleague mentioned that it might not be wise to create a short lifespan variable. But I thought that's what the compiler did anyway?
Anyway, the question is: is doing it the first way (example1) in any way detrimental to garbage collection/performance? I'm using C# but am actually curious how Java and C++ behave in the same scenario as well.