空对象是什么意思? [英] What does a null object mean?

查看:69
本文介绍了空对象是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个类的对象

If I create an object of a class

A obj = new A();

,然后我将 null 分配给它: obj = null; .

and later I assign null to it: obj = null;.

那么obj为空意味着什么?这是否意味着现在它指向无处,并且所有内存都被释放了?

Then what does it mean obj being null? Does it mean now it is pointing nowhere and all memory is deallocated?

推荐答案

obj 现在指向 null 参考存储位置.

obj now points to the null reference memory location.

从MSDN上的空(C#参考):

null关键字是一种表示空引用的文字,它不引用任何对象.

The null keyword is a literal that represents a null reference, one that does not refer to any object.

如果您尚未将其先前指向的对象分配给其他任何对象,则该对象将有资格由GC进行收集.

If you have not assigned the object it formerly pointed to to anything else, that object will be eligible for collection by the GC.

这篇关于空对象是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆