C#: In what cases should you null out references?

后端 未结 3 1063
情话喂你
情话喂你 2021-02-14 05:39

The CLR Profiler can also reveal which methods allocate more storage than you expected, and can uncover cases where you inadvertently keep references to useless o

3条回答
  •  没有蜡笔的小新
    2021-02-14 06:40

    You should null out references for object you don't need anymore when you know they won't be garbage collected otherwise.

    If you have Effective Java book, look at Item 5, there is an example of a stack implementation that has memory leaks because the objects references are not nulled out. If you don't have that book, you can look that part on Google Books here.

提交回复
热议问题