Where did variable = null as “object destroying” come from?

后端 未结 14 1662
无人共我
无人共我 2021-02-18 15:51

Working on a number of legacy systems written in various versions of .NET, across many different companies, I keep finding examples of the following pattern:

pub         


        
14条回答
  •  醉话见心
    2021-02-18 16:22

    It comes from C++ code especially smart pointers. In that case it's rougly equivalent to a .Dispose() in C#.

    It's not a good practice, at most a developer's instinct. There is no real value by assigning null in C#, except may be helping the GC to break a circular reference.

提交回复
热议问题