Consider the following example.
public void SomeMethod(){
using(var sqlConnection= new SQLConnection()){
//some code here
}
}
In the above example the sqlConnection outside the using block will be disposed and garbage collected
public void SomeMethod(){
var sqlConnection = new SQLConnection(){
}
}
In this example the sqlConnection
object will be garbage collected after the execution of SomeMethod()
.
The question here is, is it really necessary to use a using()
scope in this case as it is ok for me to have the object garbage collected at the end of execution. Could some one share your thoughts here.