查询垃圾收集器 [英] query regarding Garbage collector

查看:203
本文介绍了查询垃圾收集器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道GC释放obj的内存,这是没有使用在任何进一步,但我知道一个事情GC释放内存在形式的对象或refrence或值....
请帮助我。 / p>

提前感谢...

解决方案

对于这个问题,似乎需要澄清几个概念:



在.NET中,对象住在内存中的某处。引用类似于指向这样的对象/内存位置的指针。



例如,假设您有一个类型为 MyClass 的对象 / em>,并且您已创建一个新实例。此对象包含一个字符串。该字符串是另一个对象,您的 MyClass 实例保存对字符串对象的引用。



垃圾收集器只在对象。它跟踪对象的引用,如果没有人引用对象,垃圾回收器可以释放该对象。在我们的示例中,如果垃圾回收器注意到没有人持有对 MyClass 实例的引用,那么它确保对象被释放。这反过来使对字符串的引用消失,然后垃圾收集器也可以释放字符串(如果没有其他人持有引用,当然)。值不需要以任何特殊方式处理,因为它们是属于对象的内存的一部分(因此不能独立释放)。



Java,BTW也是如此。


i know GC release the memory of obj which is not used in any further but i know one thing that GC release memory in which form of like object or refrence or value.... please help me.

thanks in advance...

解决方案

As a response to the comments to the question, it seems that you need clarification of a few concepts:

In .NET, objects live somewhere in the memory. A reference is kind of like a pointer to such an object/memory location. A value is some integral value (a number like 123).

For example, say you have an object of type MyClass, and you have created a new instance. This object contains a string. That string is another object, and your instance of MyClass holds a reference to the string object.

The garbage collector operates only on objects. It keeps track of the references to an object, if nobody is referencing the object any more the garbage collector can free that object up. In our example, if the garbage collector notices there's nobody holding a reference to the instance of MyClass, then it makes sure that object is freed. That in turn makes the reference to the string disappear, and the garbage collector can then also free the string (if nobody else is holding a reference, of course). Values don't need to be treated in any special way as they are part of the memory that belongs to an object (and thus cannot be freed "independently").

The same is true with Java, BTW.

这篇关于查询垃圾收集器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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