Question

I don't mean to start a[nother] civil war over this issue, but should nullification be enforced or not?

While trying to fix a bug (that was fixed elsewise, as can be seen here), I added code like this in a couple of places to immediately and explicitly set some objects to null:

List<String> XMLFiles = CCRUtils.GetXMLFiles(fileType, @"\");
foreach (string fullXMLFilePath in XMLFiles)
{
    RESTfulMethods.SendXMLFile(fullXMLFilePath, uri, 500);
}
XMLFiles = null;

Now that I know that did not solve the problem I was having, should I just leave it, or remove this type of code?

Was it helpful?

Solution

should nullification be enforced or not?

In general, it should not. There are very few circumstances where there is a reason to set a variable to null. As soon as the scope in which the variable is declared ends, the reference to the object will no longer be held.

Setting a variable to null after use is (almost) always just a misunderstanding of how the GC works, and serves no purpose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top