做值类型导致GC? [英] Do ValueTypes cause GC?

查看:193
本文介绍了做值类型导致GC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有堆栈分配的值类型是什么清除它们?该GC只是堆吧?

if I have stack allocated value types what cleans them up? The GC is only heap right?

推荐答案

如果的值是在栈上,那么在当前栈帧是弹出(由该方法返回)的值有效清理......不会有任何所谓的终结之类的东西,而是使用了由这些值的内存将被重用在下一次堆得那么高。

If the values are on the stack, then when the current stack frame is "popped" (by the method returning) the values are effectively cleaned up... there won't be any finalizers called or anything like that, but the memory used up by those values will be reused next time the stack gets that high.

请注意,值类型是不的总是的分配在栈上,但是。尤其是,他们常常被分配为其他对象的一部分(例如,一个类的 INT 成员),也可以装箱。

Note that value types aren't always allocated on the stack, however. In particular, they're often allocated as part of other objects (e.g. a class with an int member) or they can be boxed.

这篇关于做值类型导致GC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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