Is variable assignment expensive compared to a null check? For example, is it worth checking that foo is not null before assigning it null?
if (foo != null)
First of all, it's micro optimization. So no need to worry much about it.
But to answer your question, you need to reduce it to just one line. (as all your code does is to set it to NULL).
foo = NULL;
Reasons being that,
Comparison is a much much costlier operation than assignment. (As comparison eats up many assembly instructions comparatively. Generally a subtraction and a comparison to zero or an XOR and comparison to zero). Assignment takes up fewer instructions.