Jigar Naik
That will happen anyways when the variable goes out of scope. Setting it to null in such a case is just plain silly.Jeremie Blais wrote:When you set a variable to null, you are telling the garbage collector that you don't need that variable anymore. When the garbage collector notices that you don't need that variable, it will consider the memory taken by the variable as free and it will allocate it for something else when it is needed.
Jeremie Blais wrote:When you set a variable to null, you are telling the garbage collector that you don't need that variable anymore.
Ernest Friedman-Hill wrote:This kind of thing is a terrible anti-pattern; it's pretty much cargo-cult programming.
Ernest Friedman-Hill wrote:
Returning from the method in which the local variable is declared has the same effect, without running any extra code. This kind of thing is a terrible anti-pattern; it's pretty much cargo-cult programming.
Here, the variables will disappear immediately after the nulling code, and so that's just silly.
I disagree. It adds to code bloat and makes the code unnecessarily complex and confusing. Especially to those that don't know any better. Look at the code that started this thread. You find all the unnecessary try and catching in it acceptable?Jeremie Blais wrote:There is no harm in always nulling variables out.
Bear Bibeault wrote:I disagree. It adds to code bloat and makes the code unnecessarily complex and confusing. Especially to those that don't know any better. Look at the code that started this thread. You find all the unnecessary try and catching in it acceptable?
Bear Bibeault wrote:Look at the code that started this thread. You find all the unnecessary try and catching in it acceptable?
Jigar Naik
Already answered. Unnecessary. Confusing. Obfuscating. Bloated. Silly.Jeremie Blais wrote:My question is, if we always have to explicitely initialize variables, why is it bad to explicitely null out variables when we are done with them?