Kumari Priyanka wrote:yes.....gc will take care of the short lived references.....but the first is the best practice that you should follow......
I disagree. If a variable is meant to be limited to a certain scope it shouldn't be declared outside of that scope, because it may then inadvertently escape its inteded scope.
If you minimize the scope of the variable this cannot happen and the variable will be more readily recognizable as a local variable to programmers that will have to maintain the code.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.