Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting objects to nothing

Tags:

.net

vb.net

This is something i seeem to get a different answer for, every time i ask a developer. So i thought it would be a good question for the overflow to see what everyone does.

If you have a sqlClient.sqlconnection object, in the cleanup code (finally block etc) do you dispose of the object or do you set it to nothing, or both?

I've always just called the dispose, and allowed the garbage collector to do its thing...

like image 429
GordonB Avatar asked May 06 '26 12:05

GordonB


1 Answers

Have a look at my answer to a similar question. Setting a variable to null/Nothing is very rarely necessary. Calling Dispose is necessary.

like image 103
Jon Skeet Avatar answered May 08 '26 02:05

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!