开发者

Do ValueTypes cause GC?

开发者 https://www.devze.com 2023-02-09 10:42 出处:网络
开发者_如何学JAVAif 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 ret
开发者_如何学JAVA

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.

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.


Stack allocated values disappear automatically with the stack frame they are contained in (i.e. when you return from the method).


stack works automatically, no need of explicit memory deallocation

0

精彩评论

暂无评论...
验证码 换一张
取 消